#! /bin/bash
#
# @config_gfarm_gfsd_rc_name@     Start the gfsd server.
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=gfsd
FILE="@config_gfarm_gfsd_rc_name@" # usually "gfsd", or maybe "gfsd-IP_ADDRESS"
DAEMON="@config_gfarm_prefix@/sbin/$NAME"
PIDFILE="@config_gfarm_gfsd_pid_file@"
CONF="@config_gfarm_gfarm_config@"
OPTIONS="@config_gfarm_gfsd_option@"

trap "" 1
export LANG=C
export PATH

# gfsd service certificate
export X509_USER_CERT=/etc/grid-security/@config_gfarm_gfsd_rc_name@/gfsdcert.pem
export X509_USER_KEY=/etc/grid-security/@config_gfarm_gfsd_rc_name@/gfsdkey.pem

test -f $DAEMON || exit 0
test -f $CONF || exit 0

# status_of_proc
. /lib/lsb/init-functions

case "$1" in
  start)
	echo -n "Starting gfarm server: $FILE"
	start-stop-daemon --quiet --start \
             --pidfile $PIDFILE --exec $DAEMON -- -P $PIDFILE $OPTIONS
	echo "."
	;;
  stop)
	echo -n "Stopping gfarm server: $FILE"
	start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
	echo "."
	;;
  status)
	status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart}"
	exit 1
	;;
esac

exit 0
