-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathctlwatchers
executable file
·79 lines (66 loc) · 1.72 KB
/
ctlwatchers
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
#!/bin/bash
export PATH=/usr/bin:/bin
cd $( dirname $0 )
mkdir -p run
isrunning() {
local bn="$1"
echo -n "$bn: "
if [ -s "run/$bn.pid" ] && kill -0 $( cat "run/$bn.pid" 2>/dev/null ) 2>/dev/null; then
cat /proc/$( cat "run/$bn.pid" )/cmdline | grep -q "$bn"
if [ $? -eq 0 ]; then
echo "running (pid $( cat "run/$bn.pid" ))"
return 0
fi
fi
echo not running
return 1
}
case "$1" in
start-if-not-running )
for watcher in bin/watch-for-*; do
bn=$( basename "$watcher" )
if ! isrunning "$bn" >/dev/null 2>&1 ; then
echo "$bn starting"
nohup $watcher >> run/log.out 2>&1 &
echo $! > "run/$bn.pid"
disown
else
echo "$bn already running"
fi
done
;;
start )
for watcher in bin/watch-for-*; do
bn=$( basename "$watcher" )
echo "$bn starting"
nohup $watcher >> run/log.out 2>&1 &
echo $! > "run/$bn.pid"
disown
done
;;
stop )
for pidfile in run/*.pid; do
if [ -s "$pidfile" ]; then
bn=$( basename "$pidfile" .pid )
echo "$bn stopping"
kill $( cat "$pidfile" )
fi
rm -f "$pidfile"
done
;;
status )
for watcher in bin/watch-for-*; do
bn=$( basename "$watcher" )
isrunning "$bn"
done
;;
restart )
$0 stop
sleep 1
$0 start
;;
* )
echo "$0 [start|stop|status|restart|start-if-not-running|help]" >&2
;;
esac
# vim: ts=4 expandtab