#!/bin/sh
#
# chkconfig: - 42 3
# description: Starts and stops all services needed for lafet
# processname: lafet
# pidfile: /var/run/lafet.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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


# project source function library.
. ctl-functions-lafet.sh

PROJECT=lafet
LOCKFILE=/var/lock/subsys/$PROJECT-sm
RETVAL=0

start()
{
	# check network
#   if ! ping -c 1 localhost 2>/dev/null 1>/dev/null; then
#		service network restart
#   fi
	
	# start
	if ! [ -e "$LOCKFILE" ]; then
		$BINDIR/ctl-sm-lafet.sh start 2>/dev/null
	else
		passed "${PROJECT}-sm startup"
	fi
}

stop()
{
	if ! [ -e "$LOCKFILE" ]; then
		$BINDIR/ctl-sm-lafet.sh stop 2>/dev/null
	else
		passed "${PROJECT}-sm stopped"
	fi
}

restart()
{
	stop
	start
}

status()
{
	$BINDIR/ctl-monit-lafet.sh status
	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	status)
		status
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
