-
Notifications
You must be signed in to change notification settings - Fork 4
/
svc-noip2
executable file
·70 lines (58 loc) · 1.31 KB
/
svc-noip2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env bash
#
#. /lib/svc/share/smf_include.sh
set -e
CONF_FILE="/usr/local/etc/no-ip2.conf"
ENV="/usr/bin/env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin:/opt/sfw/bin:/usr/sfw/bin"
function checkconfig() {
if [ ! -e "$CONF_FILE" ] ; then
echo "You need a /usr/local/etc/no-ip2.conf file to run noip2"
return 1
fi
}
function killRunning() {
declare -a PIDS=($(pgrep noip2))
if [ ${#PIDS[@]} -gt 0 ]; then
echo "noip2 already running, killing"
for pid in ${!PIDS[*]}
do
echo "running: /usr/local/bin/noip2 -K ${PIDS[$pid]}"
eval $ENV /usr/local/bin/noip2 -K ${PIDS[$pid]} > /dev/null 2>&1
done
# wait and call self
sleep 2
killRunning
else
return 0
fi
return 0
}
function start() {
checkconfig || return 1
killRunning || return 1
echo "Starting noip2 with $CONF_FILE"
eval $ENV /usr/local/bin/noip2 &
}
function stop() {
echo "Stopping noip2"
# send sterr/out to dev/null in case there is no currently running noip2 process
eval $ENV /usr/local/bin/noip2 -K $(pgrep -o -U nobody noip2) > /dev/null 2>&1
}
case $1 in
start)
start
;;
stop)
stop
;;
restart) # not actually called by SMF
echo "Restarting noip2 with $CONF_FILE"
stop
sleep 2
start
;;
*)
echo "Usage: /lib/svc/method/svc-noip2 start|stop|restart" >&2
exit 2
;;
esac