#!/bin/bash
#
# 
#
# chkconfig: 345 24 76
# description: start/stop the gulm lock daemon
#
#	       
### BEGIN INIT INFO
# Provides: 
### END INIT INFO

. /etc/init.d/functions

start()
{
	sts=1
	echo -n "Starting lock_gulmd:"
	if lock_gulmd &> /dev/null
	then
		for i in $(seq 1 10)
		do
			sleep 1
			if gulm_tool getstats localhost:ltpx &> /dev/null
			then
				sts=0
				break
			fi
		done
	fi
	if [ $sts -eq 0 ]
	then
		success
	else
		failure
	fi
	echo
	return $sts
}

stop()
{
	sts=1
	echo -n "Stopping lock_gulmd:"
	if gulm_tool shutdown localhost &> /dev/null
	then
		for sec in $(seq 1 10 )
		do
			sleep 1
			if ! gulm_tool shutdown localhost &> /dev/null
			then
				success
				echo
				sts=0
				break
			fi
		done
	fi

	if [ $sts -ne 0 ]
	then
		failure
		echo
	fi
	return $sts
}	

rtrn=1

# See how we were called.
case "$1" in
  start)
	start
	rtrn=$?
	[ $rtrn -eq 0 ] && touch /var/lock/subsys/lock_gulmd
	;;

  stop)
	stop
	rtrn=$?
	[ $rtrn -eq 0 ] && rm -f /var/lock/subsys/lock_gulmd
	;;

  restart)
	$0 stop
	$0 start
	rtrn=$?
	;;

  status)
	status lock_gulmd
	rtrn=0
	;;

  *)
	echo $"Usage: $0 {start|stop|restart|status}"
	;;
esac

exit $rtrn

