#!/bin/bash
#
# rpcfedfsd     Start up and shut down FedFS admin service
#
# chkconfig: 345 19 83
# description: Starts user-level daemon that handles FedFS administrative requests

### BEGIN INIT INFO
# Provides: rpcfedfsd
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start: 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts the rpc.fedfsd daemon
# Description: Starts daemon that processes FedFS administrative \
#          requests shared file system exports.
### END INIT INFO

##
## Copyright 2011 Oracle.  All rights reserved.
##
## rpcfedfsd is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License version 2.0 as
## published by the Free Software Foundation.
##
## rpcfedfsd is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License version 2.0 for more details.
##
## A copy of the GNU General Public License version 2.0 is
## available here:
##
##      http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
##

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

# Source networking configuration.
[ -f /etc/sysconfig/network ] &&  . /etc/sysconfig/network

# Check for, and source, configuration file; otherwise set defaults
[ -f /etc/sysconfig/fedfs ] && . /etc/sysconfig/fedfs

RETVAL=0
prog="rpc.fedfsd"
LOCKFILE=/var/lock/subsys/$prog
uid=`id | cut -d\( -f1 | cut -d= -f2`

case "$1" in
  start|condstart)
	# Check that networking is up.
	[ "${NETWORKING}" != "yes" ] && exit 6

	[ ! -x /usr/sbin/rpc.fedfsd ] && exit 5

	# Only root can start the service
	[ $uid -ne 0 ] && exit 4

	# Make sure the daemon is not already running.
	[ "$1" = "condstart" -a -n "`pidofproc $prog`" ] && {
		killproc $prog "-SIGHUP" > /dev/null
		exit 0
	}
	[ "$1" = "start" ] && {
		if status $prog > /dev/null ; then
			exit 0
		fi
	}
	rm -f $LOCKFILE

	echo -n $"Starting RPC fedfsd: "

	# Start daemon.
	daemon $prog ${RPCFEDFSDARGS}
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch $LOCKFILE
	;;
  stop)
	# Only root can stop the service
	[ $uid -ne 0 ] && exit 4

	# Stop daemon.
	echo -n $"Stopping RPC fedfsd: "
	killproc $prog
	RETVAL=$?
	echo
	rm -f $LOCKFILE
	;;
  status)
	status rpc.fedfsd
	RETVAL=$?
	;;
  restart|reload|force-reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  condrestart|try-restart)
	if [ -f $LOCKFILE ]; then
		$0 restart
		RETVAL=$?
	fi
	;;
  condstop)
	if [ -f $LOCKFILE ]; then
		$0 stop
		RETVAL=$?
	fi
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|force-reload|condstart|condrestart|try-restart|status|condstop}"
	RETVAL=2
	;;
esac

exit $RETVAL
