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

action=$1

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

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="mountd nfsd"
fi


case $action in
	start)
		started=
		for p in $PROCS
		do
			it=`pathof $p /etc:/etc/daemons:$TCPLIB`
			if [ -n "$it" -a "`pidof $p`" = "" ]; then
				if [ -z "$started" ]; then
					echo $use_escapes "Starting NFS services: \c"
					started=yes
				fi
				$it
				echo $use_escapes " $p\c"
			fi
		done
		if [ -n "$started" ]; then
			echo " ... done"
		fi
		;;

	stop)
		stopped=
		for p in $PROCS
		do
			for i in `pidof $p`
			do
				kill $i
				if [ -z "$stopped" ]; then
					stopped=yes
				fi
			done
		done

		if [ -n "$stopped" ]; then
			echo "NFS services stopped"
		fi
		;;

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