-
Notifications
You must be signed in to change notification settings - Fork 0
/
wapyd
executable file
·113 lines (98 loc) · 2.17 KB
/
wapyd
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/bash
start() {
if [[ $1 == "" ]]
then
num='1'
else
num=$1
fi
gearman_pid=`pgrep gearman`
if [[ $gearman_pid == "" ]]
then
echo "Warning : gearman not running on this server"
fi
dirs_ok=false
for rep in /var/log
do
if test -d $rep && test -w $rep
then
dirs_ok=true
else
dirs_ok=false
fi
done
if [[ $dirs_ok ]]
then
for i in `seq 1 $num`
do
if [ "$(uname)" == 'Darwin' ]
then
/usr/local/wapy/wapy_worker.py $i &
else
/sbin/start-stop-daemon -d /usr/local/wapy -c wapyd:adm -x ./wapy_worker.py -S -- $i &
fi
done
status
else
echo "Some system dirs are not writeable, launch this script with root user"
fi
}
stop() {
pid=`pgrep -f wapy_worker.py`
if [[ $pid == "" ]]
then
echo "No process running, use start to launch python worker"
exit 1
else
for runPid in $pid
do
kill $runPid
done
fi
echo "Worker stopped" >>/var/log/wapyd.log
}
status() {
gearman_pid=`pgrep gearman`
if [[ $gearman_pid == "" ]]
then
echo "gearman not running on this server"
else
echo "gearman running, pid $gearman_pid"
fi
redis_pid=`pgrep redis`
if [[ $redis_pid == "" ]]
then
echo "redis not running"
else
echo "redis running, pid $redis_pid"
fi
pid=`pgrep -f wapy_worker.py`
if [[ $pid == "" ]]
then
echo "No process running"
exit 1
else
arr=($pid)
set -- $pid
echo ${#arr[@]}" workers running, pids "$pid
fi
echo "Worker stopped" >>/var/log/wapyd.log
}
case $1 in
start)
start $2
;;
stop)
stop
;;
restart)
stop; start;
;;
status)
status
;;
*)
echo "You must give a command : start [number of worker to start], stop, restart or status"
;;
esac
exit 1