#!/bin/sh
#
# chkconfig:	345 91 35
# description:	Starts and stops the OpenH323 gatekeeper 
#

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

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

# Source networking configuration.
. /etc/sysconfig/network

# Demon specified configuration.
. /etc/sysconfig/gnugk

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network ]; then
		msg_network_down "OpenH323 gatekeeper"
		exit 1
	fi
else
	exit 0
fi

TMPDIR="/tmp"; export TMPDIR
cd /

# Check that gatekeeper.ini exists
[ -f /etc/gnugk.ini ] || exit 0

RETVAL=0
case "$1" in
  start)
	if [ ! -f /var/lock/subsys/gnugk ]; then
		msg_starting "OpenH323 gatekeeper"
		daemon "su nobody -s /bin/sh -c '/usr/sbin/gnugk -c /etc/gnugk.ini &'"
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/gnugk
	else
		msg_already_running "OpenH323 gatekeeper"
	fi
	;;
  stop)
	if [ -f /var/lock/subsys/gnugk ]; then
		msg_stopping "OpenH323 gatekeeper"
		killproc gnugk
		rm -f /var/lock/subsys/gnugk >/dev/null 2>&1
	else
		msg_not_running "OpenH323 gatekeeper"
	fi
	;;
  status)
	status gnugk
	exit $?
	;;
  restart)
	$0 stop
	$0 start
	exit $?
	;;
  reload|force-reload)
	if [ -f /var/lock/subsys/gnugk ]; then
		msg_reloading "OpenH323 gatekeeper"
		killproc gnugk -HUP
		RETVAL=$?
	else
		msg_not_running "OpenH323 gatekeeper" >&2
		exit 7
	fi
	;;
  *)
	msg_usage "$0 {start|stop|restart|reload|force-reload|status}"
	exit 3
esac

exit $RETVAL
