]> git.decadent.org.uk Git - nfs-utils.git/blob - etc/nodist/nfs-server
mount nfsd filesystem at startup, and unmount afterwards
[nfs-utils.git] / etc / nodist / nfs-server
1 #!/bin/sh
2 # nfs   This shell script starts and stops the nfs services in a distribution
3 #       independent fashion.
4 #
5 # description:  starts and stops nfs server services
6 # chkconfig: 2345 60 20
7 #
8 # Copyright (c) 2000-2001 Mission Critical Linux, Inc.
9 #
10
11 PATH=/sbin:/bin:/usr/sbin:/usr/bin
12 export PATH
13
14 # Who am I?
15 SCRIPT_NAME=`basename $0`
16
17 # Grab our daemon functions.
18 . `dirname $0`/nfs-functions
19
20 # Kernel daemons and options
21 PREFIX="rpc."           # Prefix for kernel execs (usually "rpc.")
22 NFSD="nfsd"             # Kernel NFS Server
23 RPCNFSDCOUNT="8"        # Number of nfsd threads
24
25 # User daemons and options
26 RQUOTAD="rpc.rquotad"   # Remote quota server
27 MOUNTD="rpc.mountd"     # Mount server
28 RPCMOUNTDOPTS=""        # options for rpc.mountd
29 EXPORTFS="exportfs"     # Exportfs command
30
31 SCRIPT_NAME=`basename $0`
32 DESC="NFS kernel daemon"
33
34 # We use "type -path" instead of "which" since it's internal to bash.
35 [ -x "`type -path $PREFIX$NFSD`" ] || exit 0
36 [ -x "`type -path $MOUNTD`" ] || exit 0
37
38 # Also make sure we have our exportfs command.
39 [ -x "`type -path $EXPORTFS`" ] || exit 0
40 [ -s /etc/exports ] || exit 0
41
42 # rquotad is not required for NFS to work, however.
43 # Unset if it is not present.
44 [ -x "`type -path $RQUOTAD`" ] || unset RQUOTAD
45
46 # Handle how we were called.
47 case "$1" in
48 start)
49     if [ -d /proc/fs/nfsd -a ! -f /proc/fs/nfsd/exports ] ;
50     then
51          /bin/mount -t nfsd nfsd /proc/fs/nfsd
52     fi
53     echo -n "Exporting directories for $DESC..."
54     $EXPORTFS -r
55     echo "done."
56
57     echo -n "Starting $NFSD: "
58     startdaemon $PREFIX$NFSD $RPCNFSDCOUNT
59
60     # Disable NFSv3 on mountd if we don't have NFSv3
61     ClearAddr=
62     if [ -f /proc/net/rpc/auth.unix.ip/channel ] ; then
63       if   grep -s 127.0.0.1 /proc/net/rpc/auth.unix.ip/content > /dev/null ; then
64              : address already known
65       else
66              echo nfsd 127.0.0.1 2147483647 localhost > /proc/net/rpc/auth.unix.ip/channel
67              ClearAddr=
68       fi
69     fi
70     rpcinfo -u localhost nfs 3 &>/dev/null 
71     if [ "$?" != "0" ]
72     then
73         RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
74     fi
75     if [ -n "$ClearAddr" ]; then
76           echo nfsd 127.0.0.1 1  > /proc/net/rpc/auth.unix.ip/channel
77     fi
78
79     echo -n "Starting $MOUNTD: "
80     startdaemon $MOUNTD $RPCMOUNTDOPTS
81
82     # Start rquotad if it is set
83     if [ -n "$RQUOTAD" ]
84     then
85         echo -n "Starting $RQUOTAD: "
86         startdaemon $RQUOTAD
87     fi
88
89     # if this lock file doesn't exist, init won't even try to run
90     # the shutdown script for this service on RedHat systems!
91     # on non-RedHat systems, /var/lock/subsys may not exist.
92     touch /var/lock/subsys/$SCRIPT_NAME &> /dev/null
93     ;;
94
95 stop)
96     for process in $RQUOTAD $MOUNTD $NFSD
97     do
98         echo -n "Stopping $process: "
99         stopdaemon $process
100     done
101
102     echo "Unexporting directories for $DESC..."
103     $EXPORTFS -au
104     if [ -f /proc/fs/nfsd/exports ] ; then /bin/umount -t nfsd nfsd /proc/fs/nfsd ; fi
105     rm -f /var/lock/subsys/$SCRIPT_NAME 
106     echo "done."
107     ;;
108
109 restart)
110     $0 stop
111     sleep 1
112     $0 start
113     ;;
114
115 reload)
116     # Update exports
117     echo "Re-exporting directories for $DESC..."
118     $EXPORTFS -r
119     touch /var/lock/subsys/$SCRIPT_NAME &> /dev/null
120     echo "done."
121     ;;
122
123 status)
124     # First, check status of userland daemons
125     for process in $RQUOTAD $MOUNTD $NFSD
126     do
127         daemonstatus $process
128     done
129     exit 0
130     ;;
131
132 *)
133     echo "Usage: $0 {start|stop|status|restart|reload}"
134     exit 1
135 esac