#!/bin/bash
#
# globus-gridftp-server - Globus GridFTP Server
# chkconfig: - 20 80
# description: The Globus GridFTP server is a process which implements the \
#              GridFTP protocol for secure, high-performance file transfer.
#
### BEGIN INIT INFO
# Provides:          globus-gridftp-server
# Required-Start:    $remote_fs $syslog $network
# Required-Stop:     $remote_fs $syslog
# Default-Start: 3 5
# Default-Stop:      0 1 2 3 4 5 6
# Short-Description: Globus GridFTP Server
# Description:       The Globus GridFTP server is a process which implements
#                    the GridFTP protocol for secure, high-performance file
#                    transfer.
### END INIT INFO

# source function library
. /etc/rc.status

sbindir=/usr/sbin
sysconfdir=/etc

rc=0
conf=${sysconfdir}/gridftp.conf
confdir=${sysconfdir}/gridftp.d
pidfile=/var/run/globus-gridftp-server.pid
gridftpd=${sbindir}/globus-gridftp-server

# Include defaults if available
if [ -r /etc/sysconfig/globus-gridftp-server ] ; then
	. /etc/sysconfig/globus-gridftp-server
fi

# First reset status of this service
rc_reset

case "$1" in
	start)
		echo -n "Starting globus-gridftp-server: "
		if [ ! -f $conf ]; then
			touch $conf
		fi
		if [ ! -d $confdir ]; then
			mkdir $confdir;
		fi

		if [ ! -f "$pidfile" ]; then
			startproc -f -p ${pidfile} $gridftpd -S -C $conf -C $confdir -pidfile "${pidfile}"
			rc_status -v
		else
			rc_failed 1
			rc_status -v1
			rc_exit
		fi
		;;

	stop)
		echo -n "Stopping globus-gridftp-server: "
		
		killproc -p ${pidfile} -TERM $gridftpd
		rc_status -v
		;;

	restart) 
		$0 stop
		$0 start
		rc_status
		;;


	reload) 
		echo -n "Reloading GridFTP configuration: "
		kllproc -p ${pidfile} -HUP $gridftpd
		rc_status -v
		;;

	status) 
		echo -n "Checking for service gridftpd "
		
		checkproc -p ${pidfile} $gridftpd
		rc_status -v
		;;
	*)
		echo "Usage: $0 {start|stop|status|restart|reload}"
		exit 1
		;;
esac
rc_exit
