#!/bin/sh
#
# Copyright (C) 2005-2007 Red Hat, Inc.
#
# This program is Free Software. You may modify and/or redistribute it under
# the terms of the GNU General Public License version 2, or (at your option)
# any later version.
#
# description:  Starts and stops Ricci Cluster Module - cluster monitor
# chkconfig: 2345 99 01
#

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

# Grab the network config file
. /etc/sysconfig/network

# Grab cluster start config if it exists
[ -f /etc/sysconfig/cluster ] && . /etc/sysconfig/cluster

PATH=/sbin:/bin:/usr/sbin:/usr/bin
export PATH

ID="Cluster Module - cluster monitor"
MODCLUSTERD="modclusterd"
CFG_FILE="/etc/cluster/cluster.conf"
PIDFILE="/var/run/modclusterd.pid"
LOCKFILE="/var/lock/subsys/modclusterd"

#
# Only root wants to run this...
#
[ `id -u` = 0 ] || exit 4

#
# If we're not configured, then don't start anything.
#
[ "${NETWORKING}" = "yes" ] || exit 1
#[ -f "$CFG_FILE" ] || exit 0


case $1 in
	start)
		echo -n $"Starting $ID: "
		daemon $MODCLUSTERD
		rtrn=$?
		if [ $rtrn -eq 0 ]; then
			touch $LOCKFILE
			/usr/bin/logger -t $MODCLUSTERD "startup succeeded"
		else
			/usr/bin/logger -t $MODCLUSTERD "startup failed"
			rtrn=1
		fi
		echo
	;;

	restart)
		$0 stop
		sleep 8
		$0 start
		rtrn=$?
	;;

	status)
		status $MODCLUSTERD
		rtrn=$?
	;;

	stop)
		echo -n "Shutting down $ID: "
		killproc $MODCLUSTERD SIGTERM
		rtrn=$?
		if [ $rtrn -eq 0 ]; then
			rm -f $PIDFILE
			rm -f $LOCKFILE
			/usr/bin/logger -t $MODCLUSTERD "shutdown succeeded"
		else
			/usr/bin/logger -t $MODCLUSTERD "shutdown failed"
			rtrn=1
		fi
		echo
	;;

	condrestart)
		if [ -f ${PIDFILE} ] ; then
			$0 restart
			rtrn=$?
		fi
	;;

	reload)
		rtrn=3
	;;

	*)
		echo $"Usage: $0 {start|stop|reload|restart|status}"
		rtrn=3
	;;
esac

exit $rtrn
