#! /bin/sh
#
# Ejudge is a programming contest managment system.
#
# chkconfig: - 95 15
# description: Ejudge daemon - programming contests managment server
#
# Do not load RH compatibility interface.

WITHOUT_RC_COMPAT=1

. /etc/init.d/functions


SUPERSERVE_SOCKET=/var/run/ejudge/super-serve-socket
USERLIST_SOCKET=/var/run/ejudge/userlist-socket 
NEWSERVER_SOCKET=/var/run/ejudge/new-server-socket 
RETVAL=0

start() {
    start_daemon --user ejudge -- ejudge-control -f start
    RETVAL=$?
    return $RETVAL
}

stop() {
    action "Stopping ejudge-control service:" ejudge-control stop
    RETVAL=$?
    return $RETVAL
}

case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  condstop)
	if [ -e "$SUPERSERVE_SOCKET" ] || [ -e "$USERLIST_SOCKET" ] || [ -e "$NEWSERVER_SOCKET" ] ; then
                        stop
	fi
	;;
  condrestart)
	if [ -e "$SUPERSERVE_SOCKET" ] || [ -e "$USERLIST_SOCKET" ] || [ -e "$NEWSERVER_SOCKET" ] ; then
                        stop
			start
	fi
	;;
  *)
	msg_usage "${0##*/} {start|stop|restart|condstop|condrestart}"
	RETVAL=1
esac

exit $RETVAL
