#!/bin/sh
# startup script for maui
# chkconfig: 345 88 80
# description: Maui scheduler for PBS (instead of the PBS default scheduler) 

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

# let see how we were called
case "$1" in
  start) 
	echo -n "Starting maui: "
	# localize the configuration to this machine
	if [ ! -f /var/spool/maui/maui.cfg.dist ]; then
		pushd /var/spool/maui > /dev/null	
		cp maui.cfg maui.cfg.dist
		sed -e s%localhost%`hostname`% -e s%\<DOMAIN\>%`dnsdomainname`% maui.cfg.dist > maui.cfg
		popd > /dev/null
	fi

	# start up maui
	daemon /usr/sbin/maui
	echo
  ;;
  stop)
	echo -n "Stopping maui: "
	/usr/bin/schedctl -k
  ;;
  restart)
	echo "Restarting maui"
	$0 stop
	$0 start
	echo "done."
  ;;
  *)
	echo "Usage: maui {start|stop|restart}"
	exit 1
esac
