#!/bin/sh
#
# $Id: nfs,v 3.1 1993/03/17 10:14:44 mike Exp $
#
# Linux NFS start up.
# Starts the NFS daemons.
#

action=$1

# Load the library and find various programs.
. /etc/init.d/LIB

killall=`pathof killall /bin:/usr/bin`

TCPLIB=/etc

# Find out what service daemons are needed. If we don't have any
# listed in /etc/default/nfs we'll use a fairly minimal list of
# our own.
> /tmp/nfs.$$
if [ -r /etc/default/nfs ]; then
	awk '/^[ \t]*SERVICES/ { sub("^[ \t]*SERVICES", ""); print $0 }' /etc/default/nfs | while read i
	do
		echo $i >> /tmp/nfs.$$
	done
fi
PROCS="`cat /tmp/nfs.$$`"
rm -f /tmp/nfs.$$
if [ "$PROCS" = "" ]; then
	PROCS="rpc.mountd rpc.nfsd"
fi


case $action in
	start)
		started=
		for p in $PROCS
		do
			if $killall -0 $p 2> /dev/null; then
				: already running
			else
				it=`pathof $p $TCPLIB:/etc:/etc/daemons:/usr/etc`
				if [ -n "$it" ]; then
					if [ -z "$started" ]; then
						echo $use_escapes "Starting NFS services: \c"
						started=yes
					fi
					$it
					echo $use_escapes " $p\c"
				fi
			fi
		done
		if [ -n "$started" ]; then
			echo " ... done"
		fi
		;;

	stop)
		if wipeout $PROCS; then
			echo "NFS services stopped"
		else
			echo "NFS wasn't running"
		fi
		;;

	*)
		echo "usage: nfs start|stop"
		exit 1
		;;
esac
