#!/bin/sh
# chkconfig: - 98 10
# description: The rebootmgr service is monitoring all virtual servers \
#              and restart them as need. Virtual servers are using \
#              the /sbin/vreboot command to talk with the reboot manager
# processname: rebootmgr
# config: /etc/vservers
WITHOUT_RC_COMPAT=1

. /etc/init.d/functions

LOCKFILE=/var/lock/subsys/rebootmgr
RETVAL=0 

VROOTDIR=/var/lib/vservers

PIDFILE=/var/run/rebootmgr.pid
# See how we were called.
start () {
	cd /etc/vservers
	VSERVERS=
	for serv in *.conf
	do
		test -f "$serv" || continue
		
		serv=`basename $serv .conf`
		if [ -d $VROOTDIR/$serv ] ; then
			VSERVERS="$VSERVERS $serv"
		fi
	done
	start_daemon --lockfile "$LOCKFILE" --pidfile "$PIDFILE" -- rebootmgr $VSERVERS
	RETVAL=$?
	return $RETVAL

}
stop () {
	stop_daemon --lockfile "$LOCKFILE" --pidfile "$PIDFILE" -- rebootmgr
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

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

exit $RETVAL
