File rcmod_gearman_worker of Package mod_gearman
#!/bin/sh
#
# This library is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or (at
# your option) any later version.
#
# This library is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# chkconfig: 2345 85 15
# description: Mod-Gearman Worker Daemon
#
### BEGIN INIT INFO
# Provides: mod_gearman_worker
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: gearmand
# Should-Stop: gearmand
# Default-Start: 2 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Start/Stop the Mod-Gearman Worker Daemon
# Description: Mod-Gearman Worker Daemon allows to distribute
# Nagios/Icinga checks across your network and increasing the
# scalability.
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON='/usr/bin/mod_gearman_worker'
NAME='mod_gearman_worker'
CONFIG='/etc/mod_gearman/mod_gearman_worker.conf'
PIDFILE='/var/run/mod_gearman/mod_gearman_worker.pid'
USER='nagios'
USERID=$(id -u)
# Check for missing binaries
test -x $DAEMON || { echo "$DAEMON not installed";
if [ "$1" = "stop" ]; then exit 0;
else exit 5; fi; }
# load extra environment variables
if [ -f /etc/sysconfig/mod_gearman_worker ]; then
. /etc/sysconfig/mod_gearman_worker
fi
# Shell functions sourced from /etc/rc.status:
. /etc/rc.status
# Reset status of this service
rc_reset
case "$1" in
start)
echo -n "Starting $NAME "
CMD="$DAEMON -d --config=$CONFIG --pidfile=$PIDFILE"
mkdir -p $(dirname $PIDFILE)
if [ "$USERID" -eq 0 ]; then
chown $USER: $(dirname $PIDFILE)
su -s $SHELL - $USER -c "$CMD"
else
$CMD
fi
# Remember status and be verbose
rc_status -v
;;
stop)
echo -n "Shutting down $NAME "
# We should wait for mod_gearman_worker to exit and remove its
# own lockfile, otherwise a following start could happen, and then
# the existing process will remove the new lockfile, allowing
# multiple daemons to run
if checkproc "$DAEMON" ; then
/sbin/killproc -p "$PIDFILE" -TERM "$DAEMON"
sleep 1
if [ -e "$PIDFILE" ]; then
echo "Warning: $NAME did not exit in a timely manner. Waiting..."
while [ -e "$PIDFILE" ] && [ $TIMEOUT -gt 0 ] ; do
sleep 1
TIMEOUT=[$TIMEOUT-1]
echo -n "."
[ $TIMEOUT -eq 41 ] && echo
done
fi
if checkproc "$DAEMON" ; then
/sbin/killproc -p "$PIDFILE" -SIGKILL "$DAEMON"
echo -n "Warning: $NAME killed"
fi
else
echo -n "not running"
rc_failed 7
fi
rc_reset
rc_status -v
;;
reload|force-reload)
echo -n "Reloading $NAME configuration "
killproc -p "$PIDFILE" -HUP "$DAEMON"
rc_status -v
;;
status)
echo -n "Checking for $NAME "
/sbin/checkproc -p "$PIDFILE" "$DAEMON"
rc_status -v
;;
restart)
$0 stop && sleep 1 && $0 start
exit $?
;;
try-restart|condrestart)
# Do a restart only if the service was active before
if test "$1" = "condrestart"; then
echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
fi
$0 status
if test $? = 0; then
$0 restart
else
rc_reset # Not running is not a failure.
fi
# Remember status and be quiet
rc_status
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
exit 1
;;
esac
rc_exit