#! /bin/sh
# Copyright (c) 1995-2002 SuSE Linux AG, Nuernberg, Germany.
#
# Author: Ruediger Oertel <ro@suse.de>, 2002
#
# /etc/init.d/nfslock
#
### BEGIN INIT INFO
# Provides: nfslock
# Required-Start: $network portmap
# Required-Stop: $network portmap
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Description: Start the NFS locking daemon
### END INIT INFO

. /etc/sysconfig/nfs

. /etc/rc.status

# First reset status of this service
rc_reset

case `uname -r` in
    0.*|1.*|2.0.*) exit 3
esac

RPCSTATD=""
test -x /sbin/rpc.statd && RPCSTATD=/sbin/rpc.statd
RPCLOCKD=""
test -x /sbin/rpc.lockd && RPCLOCKD=/sbin/rpc.lockd

case "$1" in
    start)
	if [ -n "$RPCLOCKD" ] ; then
	    echo -n "Starting NFS file locking daemon "
	    if [ "`kernelversion`" == "2.2" ] ; then
		checkproc -n lockd || $RPCLOCKD
	    fi
	    rc_status -v
	fi
	if [ -n "$RPCSTATD" ] ; then
	    echo -n "Starting NFS stat daemon "
	    checkproc $RPCSTATD || startproc $RPCSTATD
	    rc_status -v
	fi
      ;;
    stop)
	if [ -n "$RPCLOCKD" ] ; then
	    echo -n "Shutting down NFS file locking daemon "
	    killproc -n -KILL lockd
	    rc_status -v
	fi
	if [ -n "$RPCSTATD" ] ; then
	    echo -n "Shutting down NFS stat daemon "
	    killproc    -TERM /sbin/rpc.statd
	    rc_status -v
	fi
      ;;
    try-restart)
        ## Stop the service and if this succeeds (i.e. the 
        ## service was running before), start it again.
        $0 status >/dev/null &&  $0 restart

        # Remember status and be quiet
        rc_status
        ;;
    restart|force-reload)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    reload)
	rc_failed 3
	rc_status -v
	;;
    status)
	if [ -n "$RPCLOCKD" ] ; then
	    echo -n "Checking for NFS file locking daemon: "
	    checkproc -n lockd
	    rc_status -v
	fi
	if [ -n "$RPCSTATD" ] ; then
	    echo -n "Checking for NFS stat daemon: "
	    checkproc "$RPCSTATD"
	    rc_status -v
	fi
        ;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload}"
	exit 1
	;;
esac

rc_exit
