#!/bin/sh
#
# cancd	netconsole daemon
#
# chkconfig:	2345 29 20
#
# description:	This is the CA NetConsole Daemon, \
#	a daemon to receive output from the Linux netconsole driver.
#
# $Id: cancd.init,v 1.5 2008/09/29 13:03:40 glen Exp $

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

# Get network config
. /etc/sysconfig/network

# Get service config - may override defaults
[ -f /etc/sysconfig/cancd ] && . /etc/sysconfig/cancd

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network ]; then
		msg_network_down cancd
		exit 1
	fi
else
	exit 0
fi

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/cancd ]; then
		msg_starting cancd
		daemon --user "$USER" /usr/sbin/cancd -p ${CANCD_PORT} -l "${CRASH_DIR}" -o "${CRASH_FORMAT}"
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/cancd
	else
		msg_already_running cancd
	fi
}

stop() {
	if [ -f /var/lock/subsys/cancd ]; then
		# Stop daemons.
		msg_stopping cancd
		killproc cancd
		rm -f /var/lock/subsys/cancd
	else
		msg_not_running cancd
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/cancd ]; then
		stop
		start
	else
		msg_not_running cancd
		RETVAL=$1
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status cancd
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
