#!/bin/bash
#
# rrdcached    Startup script for the rrdcached daemon
#
# chkconfig: - 85 15
# description: rrdcached is a daemon that receives updates to existing \
#	       rrd files, accumulates them, and writes updates to file
# processname: rrdcached
# config: /etc/sysconfig/rrdcached
# pidfile: /var/run/rrdcached.pid

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

if [ -f /etc/sysconfig/rrdcached ]; then
        . /etc/sysconfig/rrdcached
fi

# Path to the apachectl script, server binary, and short-form for messages.
rrdcached=/usr/sbin/rrdcached
prog=rrdcached
pidfile=/var/run/rrdcached/rrdcached.pid
sockfile=/var/run/rrdcached/rrdcached.sock
lockfile=/var/lock/subsys/rrdcached
RETVAL=0


start() {
        echo -n $"Starting $prog: "

	daemon --pidfile=${pidfile} --user=$RRDCACHED_USER \
	  $rrdcached $OPTIONS -p $pidfile -l $sockfile

        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
	[ $RETVAL = 0 ] && chmod $SOCKPERMS "${sockfile}"
        return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc -p ${pidfile} -d 10 $rrdcached
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status -p ${pidfile} $rrdcached
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  condrestart)
	if [ -f ${pidfile} ] ; then
		stop
		start
	fi
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|condrestart|status}"
	exit 1
esac

exit $RETVAL
