Merge branch 'master' of mathias-kettner.de:omd
[omd.git] / packages / mod-gearman / skel / etc / init.d / gearman_worker
blob350cb4977863136287f9ef21c76270ac834c6c20
1 #!/bin/sh
3 ### BEGIN INIT INFO
4 # Provides: mod_gearman_worker
5 # Required-Start: $local_fs
6 # Required-Stop: $local_fs
7 # Should-Start:
8 # Should-Stop:
9 # Default-Start: 2 3 4 5
10 # Default-Stop: 0 1 6
11 # Short-Description: Start/Stop the mod_gearman worker daemon
12 ### END INIT INFO
14 # Check if Mod-Gearman is enabled in OMD. If not terminate.
15 cd ###ROOT###
16 . ###ROOT###/.profile
17 . ###ROOT###/etc/omd/site.conf
18 if [ "$CONFIG_MOD_GEARMAN" != "on" -o "$CONFIG_GEARMAN_WORKER" != "on" ] ; then
19 exit 5
22 DAEMON=###ROOT###/bin/mod_gearman_worker
23 NAME=gearman_worker
24 CONFIG=###ROOT###/etc/mod-gearman/worker.cfg
25 PIDFILE=###ROOT###/tmp/run/gearman_worker.pid
26 USER=###SITE###
27 USERID=`id -u`
29 # create state dir
30 if [ "$USERID" -eq 0 ]; then
31 mkdir -p $(dirname $PIDFILE)
32 chown $USER: $(dirname $PIDFILE)
35 case "$1" in
36 start)
37 echo -n "Starting $NAME..."
38 mkdir -p ###ROOT###/tmp/run
39 mkdir -p ###ROOT###/var/log/gearman
40 rm -f ###ROOT###/var/log/mod-gearman/gearman
41 CMD="$DAEMON -d --config=$CONFIG --pidfile=$PIDFILE"
42 if [ "$USERID" -eq 0 ]; then
43 su -s $SHELL - $USER -c "$CMD"
44 else
45 $CMD
47 if [ $? -eq 0 ]; then
48 echo "OK"
49 else
50 echo "failed"
53 stop)
54 echo -n "Stopping $NAME..."
55 pid=`cat $PIDFILE 2>/dev/null`
56 if [ -z $pid ]; then
57 echo ". Not running."
58 else
59 kill $pid
60 for x in 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5; do
61 echo -n "."
62 ps -p $pid > /dev/null 2>&1 && sleep 1;
63 done
64 ps -p $pid > /dev/null 2>&1;
65 if [ $? -ne 0 ]; then
66 echo "OK"
67 exit 0;
68 else
69 echo "failed"
70 exit 1;
74 reload|force-reload)
75 echo "Reloading $NAME configuration files"
76 pid=`cat $PIDFILE 2>/dev/null`
77 if [ "$pid" != "" ]; then
78 kill -HUP $pid
81 status)
82 pid=`cat $PIDFILE 2>/dev/null`
83 if [ "$pid" != "" ]; then
84 ps -p $pid > /dev/null 2>&1
85 if [ $? -eq 0 ]; then
86 echo "$NAME is running with pid $pid"
87 exit 0;
90 echo "$NAME is not running"
91 exit 1;
93 restart)
94 $0 stop && sleep 1 && $0 start
95 exit $?
98 echo "Usage: $NAME {start|stop|status|restart}"
99 exit 1
101 esac
103 exit 0