#!/bin/sh
# Startup script for collectl
#
# chkconfig: 345 99 99
# description: Run data collection for a number of subsystems
#    see /etc/collectl.conf for startup options

RETVAL=0
COLLECTL=/usr/sbin/collectl
. /etc/rc.d/init.d/functions

if [ ! -f $COLLECTL ]; then
    echo -n "Cannot find $COLLECTL"
    exit 1
fi

case "$1" in
   start)
      echo -n "Starting collectl:"
      COMMAND="$COLLECTL -D"
      daemon $COMMAND
      RETVAL=$?
      echo
      [ $RETVAL -eq 0 ] && touch /var/lock/subsys/collectl
	;;

  stop)
      if [ -f /var/run/collectl.pid ]; then
          echo -n "Shutting down collectl: "
          killproc collectl
          RETVAL=$?
          echo
          [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/collectl
      else
          echo "collectl does not appear to be running so will not be shut down"
      fi
	;;

  flush)
      if [ -f /var/run/collectl.pid ]; then
	  pid=`cat /var/run/collectl.pid`
	  echo Flushing buffers for collectl
	  kill -s USR1 $pid
      else
	  echo "Can't find pid file /var/run/collectl.pid"
      fi
      ;;

  restart|reload)
   	$0 stop
   	$0 start
   	RETVAL=$?
	;;
  status)
   	status collectl
   	RETVAL=$?
	;;
  *)
	echo "Usage: $0 {start|stop|flush|restart|status}"
	exit 1
esac

exit $RETVAL
