#!/bin/bash
### BEGIN INIT INFO
# Provides: mon_fsstatd
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Default-Start:  1 2 3 4 5
# Default-Stop: 0 6
# Short-Description: Configure the mon_fsstatd daemon.
# Description: Configures the mon_fsstatd daemon. It uses the configuration
#              file /etc/sysconfig/mon_fsstatd
### END INIT INFO

# chkconfig: 12345 01 99

DAEMON=mon_fsstatd
DAEMON_PATH=/usr/sbin/mon_fsstatd
CONFIG_FILE=/etc/sysconfig/$DAEMON
RUN_PID_FILE=/var/run/$DAEMON.pid
RETVAL=0

# source function library
. /lib/lsb/init-functions

# Source config file
if [ -f $CONFIG_FILE ]; then
	. $CONFIG_FILE
fi

start()
{
	if [ ! -f $RUN_PID_FILE ]; then
		echo -n $"Starting $DAEMON:"
		$DAEMON_PATH $OPTIONS && log_success_msg || log_failure_msg
		echo
	else
		echo "$DAEMON (pid $(cat $RUN_PID_FILE)) is already running..."
		echo
	fi
}

stop()
{
	echo -n $"Stopping $DAEMON:"
	if [ -f $RUN_PID_FILE ]; then
		killproc $DAEMON_PATH -TERM
		log_success_msg
		rm -f $RUN_PID_FILE
	else
		log_failure_msg
	fi
	echo
}

restart() {
	stop
	start
}

status()
{
	if [ ! -f $RUN_PID_FILE ]; then
		echo "$DAEMON is not running."
		echo
	else
		echo "$DAEMON (pid $(cat $RUN_PID_FILE), options: $OPTIONS) is running."
		echo
	fi
}

# How are we called?
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status
		;;
	restart|reload)
		restart
		;;
	*)
		echo "Usage: $DAEMON {start|stop|status|restart|reload}"
		RETVAL=1
esac

exit $RETVAL
