#!/bin/bash
#
# gearmand	This shell script takes care of starting and stopping gearmand.
#
# chkconfig: 345 55 45
# description: gearman job server.
# probe: false
# processname: gearmand
# pidfile: /var/run/gearmand.pid
# config: /etc/sysconfig/gearmand
### BEGIN INIT INFO
# Provides: gearmand
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 3 4 5
# Short-Description: gearman job server.
# Description: gearman job server.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /usr/sbin/gearmand ] || exit 0

[ -f /etc/sysconfig/gearmand ] && . /etc/sysconfig/gearmand

# See how we were called.
case "$1" in
  start)
	if [ -n "`/sbin/pidof gearmand`" ]; then
            echo -n "gearmand: already running"
	    RETVAL=$?
	    echo
	    exit $RETVAL
        fi
	echo -n "Starting gearmand: "
	gearmand ${GEARMAND_OPTIONS}
	RETVAL=$?
	[ $RETVAL -eq 0 ] && success || failure
	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/gearmand
	;;
  stop)
	echo -n "Stopping gearmand: "
	killproc gearmand
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/gearmand
	;;
  status)
	status gearmand}
	RETVAL=$?
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
	echo "Usage: gearmand {start|stop|status|restart|condrestart|reload}"
	exit 1
esac

exit $RETVAL
