#!/bin/sh
#
# nfslock       This shell script takes care of starting and stopping
#               the NFS file locking service.
#
# chkconfig:	345 61 19
# description:	NFS is a popular protocol for file sharing across \
#		TCP/IP networks. This service provides NFS file \
#		locking functionality.
# probe: true

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

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/nfslock ] && . /etc/sysconfig/nfslock

# Check that networking is up.
if is_no "${NETWORKING}"; then
	msg_Network_Down "NFS lockd"
	exit 1
fi

if [ -x /sbin/pidof ] && [ "$1" != "stop" ]; then
	[ -z "`/sbin/pidof portmap`" ] && echo "Error: portmap isn't running" && exit 0
fi

# Sanity checks
[ -x /usr/sbin/rpc.statd ] || exit 0

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/nfslock ]; then
		# Start daemons.
		msg_starting "NFS statd"
		daemon rpc.statd
		touch /var/lock/subsys/nfslock
	else
		msg_Already_Running "NFS statd"
		exit 1
	fi
	;;
  stop)
  	if [ -f /var/lock/subsys/nfslock ]; then
		# Stop daemons.
		msg_stopping "NFS statd"
		killproc rpc.statd
		rm -f /var/lock/subsys/nfslock
	else
		msg_Not_Running "NFS statd"
		exit 1
	fi
	;;
  status)
	status rpc.statd
	;;
  restart)
  	$0 stop
	$0 start
	;;
  probe)
	if [ ! -f /var/lock/subsys/nfslock ] ; then
	  echo start; exit 0
	fi
	/sbin/pidof rpc.statd >/dev/null 2>&1; STATD="$?"
	if [ $STATD = 1 ] ; then
	  echo restart; exit 0
	fi
	;;
  *)
	msg_Usage "$0 {start|stop|status|restart}"
	exit 1
esac

exit 0
