#! /bin/bash
#
# gfmd     Start the gfmd server.
#

PATH=/sbin:/bin:/usr/sbin:/usr/bin
NAME=gfmd
FILE=$NAME
DAEMON="@config_gfarm_prefix@/sbin/$NAME"
PIDFILE="@config_gfarm_gfmd_pid_file@"
CONF="@config_gfarm_gfmd_config@"
OPTIONS="@config_gfarm_gfmd_option@"
export GLOBUS_THREAD_MODEL=pthread

trap "" 1
export LANG=C
export PATH

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 "."
	;;
  slavestart)
	echo -n "Starting gfarm server in slave mode: $FILE"
	start-stop-daemon --quiet --start \
             --pidfile $PIDFILE --exec $DAEMON -- -P $PIDFILE -S $OPTIONS
	echo "."
	;;
  stop)
	echo -n "Stopping gfarm server: $FILE"
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
		--retry TERM/forever/-0/1 --exec $DAEMON
	echo "."
	;;
  kill)
	echo -n "Stopping gfarm server: $FILE"
	start-stop-daemon --stop --quiet --pidfile $PIDFILE \
		--retry TERM/5/KILL/1 --exec $DAEMON
	echo "."
	;;
  status)
	status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $?
	;;
  restart|force-reload)
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: /etc/init.d/$FILE {start|slavestart|stop|kill|status|restart|force-reload}"
	exit 1
	;;
esac

exit 0
