Merge branch 'master' of mathias-kettner.de:omd
[omd.git] / packages / pnp4nagios / skel / etc / init.d / pnp_gearman_worker
blobab91bfedfc8cfc0944eeb65cbdd4aff6787f70a8
1 #!/bin/bash
3 ### BEGIN INIT INFO
4 # Provides: pnp_gearman_worker
5 # Required-Start: $all
6 # Required-Stop: $all
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 pnp4nagios gearman worker
12 ### END INIT INFO
14 #### OMD ###
15 # Check if Mod-Gearman is enabled in OMD. If not terminate.
16 cd ###ROOT###
17 . lib/omd/init_profile
18 . etc/omd/site.conf
20 if [ "$CONFIG_MOD_GEARMAN" != "on" -o "$CONFIG_PNP4NAGIOS" != "gearman" ] ; then
21 exit 5
24 ### read mod_gearman port.conf ###
25 if [ -r etc/mod-gearman/port.conf ] ; then
26 . etc/mod-gearman/port.conf
27 PORT=`echo $server | awk -F: {'print $2'}`
28 LISTEN=`echo $server | awk -F: {'print $1'}`
29 if [ -z "$LISTEN" ]; then
30 LISTEN=0.0.0.0
32 GM_PORT="--gearman=$LISTEN:$PORT"
33 else
34 GM_PORT="--gearman"
37 DAEMON="###ROOT###/lib/pnp4nagios/process_perfdata.pl"
38 CFG="###ROOT###/etc/pnp4nagios/process_perfdata.cfg"
39 NAME=pnp_gearman_worker
40 PIDFILE=###ROOT###/tmp/pnp4nagios/run/${NAME}.pid
41 USER=###SITE###
42 USERID=`id -u`
43 CMD="$DAEMON --pidfile=$PIDFILE --config=$CFG $GM_PORT --daemon"
45 function get_status() {
46 pid=`cat $PIDFILE 2>/dev/null`
47 if [ "$pid" != "" ]; then
48 ps -p $pid > /dev/null 2>&1
49 if [ $? -eq 0 ]; then
50 echo "$NAME is running with pid $pid"
51 return 0;
54 echo "$NAME is not running"
55 return 1;
58 function kill_procs() {
59 pid=`cat $PIDFILE 2>/dev/null`
60 if [ -z $pid ]; then
61 echo ". Not running."
62 else
63 # do a kill if still now down
64 ps -p $pid > /dev/null 2>&1 && kill $pid
65 for x in 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5; do
66 echo -n "."
67 ps -p $pid > /dev/null 2>&1 && sleep 1;
68 done
69 ps -p $pid > /dev/null 2>&1;
70 if [ $? -ne 0 ]; then
71 echo "OK"
72 exit 0;
73 else
74 echo "failed"
75 exit 1;
80 __init_hook $0 $1 pre
81 case "$1" in
82 start)
83 echo -n "Starting $NAME "
84 get_status > /dev/null;
85 if [ $? = 0 ]; then
86 echo "failed"
87 echo "$NAME already running"
88 exit 0;
91 if [ "$USERID" -eq 0 ]; then
92 su -s $SHELL - $USER -c "$CMD"
93 else
94 $CMD
96 if [ $? -eq 0 ]; then
97 echo "OK"
98 exit 0;
99 else
100 echo "failed"
101 exit 1;
104 stop)
105 echo -n "Stopping $NAME"
106 pid=`cat $PIDFILE 2>/dev/null`
107 if [ -z $pid ]; then
108 echo ". Not running."
109 else
110 # kill if still running
111 ps -p $pid > /dev/null 2>&1 && kill_procs;
114 status)
115 get_status;
116 exit $?;
118 restart|reload)
119 $0 stop && sleep 1 && $0 start
120 exit $?
123 echo "Usage: $NAME {start|stop|status|restart}"
124 exit 1
126 esac
128 exit 0