#! /bin/sh

# init file for ugccmon
# Copyright (C) 2012 Brainless Technologies Ltd. <www.brainless.us>
# $Id$

# For RedHat and cousins:
# chkconfig: 2345 85 15
# description: UGCC Monitor Service
# processname: mono

### BEGIN INIT INFO
# Provides: ugccmon
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: UGCC Monitor Service
# Description: The ugcc monitor service monitors game servers
#   and provides other advanced functionality.
### END INIT INFO

#Path to where monitor is installed
UGCCMONDIR=/ugcc/mon

#Mono path
MONO=/usr/bin/mono

#Set home if desired
#HOME=/root

#Don't change anything below here unless you really know what you are doing
# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="UGCC Monitor Service"
NAME=mono-service2
#Path to mono-service2
DAEMON=/usr/bin/$NAME
#Path to monitor executable
UGCCMON=$UGCCMONDIR/ugccmonsvc.exe
SCRIPTNAME=/etc/init.d/ugccmon
# Source function library
. /etc/rc.d/init.d/functions

[ -r /etc/sysconfig/ugccmon ] && . /etc/sysconfig/ugccmon

RETVAL=0
prog=ugccmon
pidfile=/var/lock/subsys/ugccmon

start()
{
        [ $UID -eq 0 ] || exit 4
        [ -x $DAEMON ] || exit 5
	if [ -e /tmp/ugccmonsvc.exe.lock ]; then
		return 1
	fi
	echo -n $"Starting $prog: "
	$DAEMON $UGCCMON -d:$UGCCMONDIR
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch $pidfile
	echo_success
	return $RETVAL
}

stop()
{
        [ $UID -eq 0 ] || exit 4
	echo -n $"Shutting down $prog: "
	killproc $MONO
	RETVAL=$?
	echo
	rm -f $pidfile
	if [ -e /tmp/ugccmonsvc.exe.lock ]; then
	 rm -f /tmp/ugccmonsvc.exe.lock
	fi

	return $RETVAL
}

reload()
{
	
	return 0
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		restart
		;;
	restart)
		stop
		start
		;;
	condrestart|try-restart)
		if [ -f $pidfile ]; then
			stop
			start
		fi
		;;
	force-reload)
		reload || (stop; start)
		;;
	status)
		status $MONO
		RETVAL=$?
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|status|condrestart|try-restart|reload|force-reload}"
		RETVAL=2
		[ "$1" = 'usage' ] && RETVAL=0
esac

exit $RETVAL
