4 # Provides: pnp_gearman_worker
9 # Default-Start: 2 3 4 5
11 # Short-Description: Start/Stop the pnp4nagios gearman worker
15 # Check if Mod-Gearman is enabled in OMD. If not terminate.
17 . lib
/omd
/init_profile
20 if [ "$CONFIG_MOD_GEARMAN" != "on" -o "$CONFIG_PNP4NAGIOS" != "gearman" ] ; then
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
32 GM_PORT
="--gearman=$LISTEN:$PORT"
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
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
50 echo "$NAME is running with pid $pid"
54 echo "$NAME is not running"
58 function kill_procs
() {
59 pid
=`cat $PIDFILE 2>/dev/null`
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
67 ps
-p $pid > /dev
/null
2>&1 && sleep 1;
69 ps
-p $pid > /dev
/null
2>&1;
83 echo -n "Starting $NAME "
84 get_status
> /dev
/null
;
87 echo "$NAME already running"
91 if [ "$USERID" -eq 0 ]; then
92 su
-s $SHELL - $USER -c "$CMD"
105 echo -n "Stopping $NAME"
106 pid
=`cat $PIDFILE 2>/dev/null`
108 echo ". Not running."
110 # kill if still running
111 ps
-p $pid > /dev
/null
2>&1 && kill_procs
;
119 $0 stop
&& sleep 1 && $0 start
123 echo "Usage: $NAME {start|stop|status|restart}"