blob: d006b9dc3bf2474a8b462d2d3e40c709a97ab383 (
plain)
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
71
72
73
74
75
76
77
78
79
80
|
#!/bin/sh
PROGNAME=ping903
COMMAND=/usr/sbin/ping903
OPTIONS=
CONFIG=/etc/ping903.conf
if [ ! -f $CONFIG ]; then
exit
fi
PIDFILE=$(sed -r -n 's/^[[:space:]]*pidfile[[:space:]]+//p' $CONFIG)
ping903_start() {
$COMMAND $OPTIONS
}
ping903_stop() {
if [ -n "$PIDFILE" ]; then
if [ -f "$PIDFILE" ]; then
pid=$(head -1 $PIDFILE)
prog=$(ps -p $pid -ocomm=)
if [ $prog = $PROGNAME ]; then
kill -TERM $pid
return
fi
else
return
fi
fi
killall $PROGNAME
}
ping903_restart() {
ping903_stop
sleep 1
ping903_start
}
ping903_status() {
if [ -n "$PIDFILE" ]; then
if [ -f "$PIDFILE" ]; then
pid=$(head -1 $PIDFILE)
prog=$(ps -p $pid -ocomm=)
if [ $prog = $PROGNAME ]; then
echo "$PROGNAME is running (PID $pid)"
else
echo "$PROGNAME is not running (pidfile is stale)"
fi
else
echo "$PROGNAME is not running"
fi
else
pid=$(/sbin/pidof $PROGNAME | cut -d ' ' -f 1)
if [ -n "$pid" ]; then
echo "$PROGNAME is running (PID $pid)"
else
echo "$PROGNAME is not running"
fi
fi
}
case "$1" in
'start')
ping903_start
;;
'stop')
ping903_stop
;;
'restart')
ping903_restart
;;
'status')
ping903_status
;;
*)
echo "usage $0 start|stop|restart|status"
esac
|