#!/bin/sh
#
# cfservd
#
# chkconfig: 345 96 03
# description:	cfservd
# processname: cfservd
# config: /var/cfengine/inputs/cfagent.conf
# pidfile: /var/run/cfservd.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

PIDFILE=/var/run/cfservd.pid
RETVAL=0

start()
{
        /usr/sbin/cfservd
	RETVAL=$?
        PID=`pidof cfservd` 2>/dev/null
        if [ "x$PID" != "x" ]; then
            echo $PID >| $PIDFILE
            msg_starting cfservd
            echo_success
            echo
            return $RETVAL
        fi
        echo_failure
        echo
}

stop()
{
    if [ ! -e $PIDFILE ]; then
        msg_stopping cfservd
        echo_passed
        echo
        return 0
    fi
        kill `cat $PIDFILE`
        RETVAL=$?
        if [ $RETVAL -eq 0 ]; then
            rm -f $PIDFILE
        fi
        msg_stopping cfservd
        echo_success
        echo
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
    :
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
        condstop)
               stop
               ;;
       condrestart)
               restart
               ;;
       condreload)
               reload
               ;;
	status)
                pidof cfservd >/dev/null 2>&1
                if [ $? -eq 0 ]; then
                    if [ -e $PIDFILE ]; then
                        echo "Cfservd is running"
                    else
                        echo "Cfservd is running, but there is no pidfile"
                    fi
                else
                    if [ -e $PIDFILE ]; then
                        echo "Cfservd is not running, but there is stale pidfile"
                    else
                        echo "Cfservd is not running"
                    fi
                fi
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
