#!/bin/sh
#
# maui	This script will start and stop the MOAB Scheduler
#
# chkconfig: 345 85 85
# description: maui
#
# 1995-2002, 2008 SUSE Linux Products GmbH, Nuernberg, Germany.
# All rights reserved.
#
# Author: Stanislav Brabec, feedback to http://www.suse.de/feedback
#
### BEGIN INIT INFO
# Provides:          maui
# Required-Start:    pbs_server
# Should-Start:      $network $remote_fs
# Required-Stop:     pbs_server 
# Should-Stop:       $network $remote_fs
# Default-Start:     3 5
# Default-Stop:
# Short-Description: Maui Cluster Scheduler
# Description:       Maui cluster scheduler and workload manager.
### END INIT INFO

ulimit -n 32768
# Source the library functions
. /etc/rc.status
rc_reset

MOAB_BIN=/usr/sbin/maui
test -x $MOAB_BIN || { echo "MOAB_BIN not installed";
         if [ "$1" = "stop" ]; then exit 0; else exit 5; fi; }
 
MOAB_CONFIG=/etc/sysconfig/maui
test -r $MOAB_CONFIG || { echo "$MOAB_CONFIG not existing";
         if [ "$1" = "stop" ]; then exit 0; else exit 6; fi; }
 
 # Read config
. $MOAB_CONFIG

export MOABHOMEDIR

# let see how we were called
case "$1" in
    start)
        echo -n "Starting Maui scheduler daemon"
        startproc $MOAB_BIN $MOAB_FLAGS 1>/dev/null
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down Maui shceduler daemon"
        killproc -TERM $MOAB_BIN
	sleep 2
        rc_status -v
        ;;
    try-restart)
        $0 status >/dev/null &&  $0 restart
        rc_status
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    force-reload)
        echo -n "Reload service Maui scheduler"
        checkproc $MOAB_BIN
        rc_status -v
        ;;
    reload)
        rc_status -v
        ;;
    status)
        echo -n "Checking for Maui scheduler: "
        checkproc $MOAB_BIN
        rc_status -v
        ;;
    probe)
        ;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
        exit 1
        ;;
esac

