#!/bin/bash
#
# globus-gatekeeper
#
# chkconfig: 2345 20 80
# description: Controls the globus-gatekeeper
#
### BEGIN INIT INFO
# Provides:          globus-gatekeeper
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Globus Gridftp Server
# Description:       Globus Gridftp Server
### END INIT INFO

# source function library
. /lib/lsb/init-functions

if [ -r /etc/default/globus-gatekeeper ] ; then
    . /etc/default/globus-gatekeeper
fi

if [ "x$RUN" != "xyes" ] ; then
    log_warning_msg "globus-gatekeeper disabled, please adjust the configuration to your needs "
    log_warning_msg "and then set RUN to 'yes' in /etc/default/globus-gatekeeper to enable it."
    log_warning_msg "See /usr/share/doc/globus-gatekeeper/README.Debian for details."
    exit 0
fi

sbindir="/usr/sbin"
sysconfdir="/etc"
localstatedir="/var"

rc=0
conf=${sysconfdir}/globus-gatekeeper.conf
pidfile=${localstatedir}/run/globus-gatekeeper.pid
gatekeeper=${sbindir}/globus-gatekeeper

start() {
	echo -n "Starting globus-gatekeeper"

	$gatekeeper -c $conf
	rc=$?

	[ $rc -eq 0 ] && log_success_msg || log_failure_msg
	[ $rc -eq 0 ] && touch /var/lock/globus-gatekeeper

	return $rc
}

stop() {
	echo -n "Stopping globus-gatekeeper"
	killall -s INT $gatekeeper 2>/dev/null
	rc=$?
	sleep 2
	killall -s KILL $gatekeeper 2>/dev/null

	[ $rc -eq 0 ] && log_success_msg || log_failure_msg
	[ $rc -eq 0 ] && rm /var/lock/globus-gatekeeper

	return $rc
}

restart() {
	stop
	start
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	;;
    restart | force-reload)
	restart
	;;
    condrestart | try-restart)
	[ -e /var/lock/globus-gatekeeper ] && restart
	;;
    reload)
	;;
    *)
	echo "Usage: $0 {start|stop|status|restart|force-reload|condrestart|try-restart|reload}"
	exit 1
	;;
esac
exit $rc
