#!/bin/bash

# Init file for Intranet Chat server daemon
#
# chkconfig: 2345 55 25
# description: Intranet Chat server daemon
#
# processname: ichatsrvd.bin
# pidfile: /var/run/ichatsrvd.pid

# source function library
. /etc/rc.d/init.d/functions

PID_FILE=/var/run/ichatsrvd.pid
RETVAL=0

# Some functions to make the below more readable


case "$1" in
	start)
		
		echo -n "Starting Intranet Chat server: "
		if [ ! -f $PID_FILE ] ; then
			/usr/bin/ichatsrvd.bin && success && touch /var/lock/subsys/ichatsrvd.bin || failure
			touch /var/lock/subsys/ichatsrvd.bin
		fi
		echo
		;;
	stop)
		echo -n "Shutting down Intranet Chat server: "
#		if [ -f $PID_FILE ] ; then
			killall -9 ichatsrvd.bin
			rm -rf $PID_FILE && success
			[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ichatsrvd.bin
#		fi
		echo
		;;
	restart)
		$0 stop
		$0 start
		;;
	*)
		echo "Usage: ichatsrvd {start|stop|restart}"
		exit 1
		;;
esac

exit $RETVAL
