#!/bin/sh
#
# lstatd	This shell script takes care of starting and stopping
#		lstat daemon.
#
# chkconfig:	2345 85 15
#
# description:	Lstatd is part of LinuxStat, system for collecting and displaing \
#		statistic data.

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

lstatd_name="lstatd.pl"
lstatd="/usr/bin/$lstatd_name"
pidfile=/var/run/lstatd.pid
flags=''

start() {
	if [ ! -f /var/lock/subsys/lstatd ]; then
		msg_starting lstatd
		daemon $lstatd $flags
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/lstatd && pidof -x $lstatd_name > $pidfile
	else
		msg_already_running lstatd
	fi
}

stop() {
	if [ -f /var/lock/subsys/lstatd ]; then
		msg_stopping lstatd
		killproc lstatd
		rm -f $pidfile /var/lock/subsys/lstatd >/dev/null 2>&1
	else
		msg_not_running lstatd
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|force-reload)
	stop
	start
	;;
  status)
	status $lstatd_name
	exit $?
	;;
  debug)
	# set debug flag
	flags='-d 1'
	start
	;;
  moredebug)
	flags='-d 2'
	start
	;;
  *)
	msg_usage "$0 {start|stop|restart|force-reload|status|debug|moredebug}"
	exit 3
esac

exit $RETVAL
