]> git.decadent.org.uk Git - nfs-utils.git/blob - etc/redhat/nfs.init
2002-04-07 H.J. Lu <hjl@lucon.org>
[nfs-utils.git] / etc / redhat / nfs.init
1 #!/bin/sh
2 #
3 # nfs           This shell script takes care of starting and stopping
4 #               the NFS services.
5 #
6 # chkconfig: - 60 20
7 # description: NFS is a popular protocol for file sharing across TCP/IP \
8 #              networks. This service provides NFS server functionality, \
9 #              which is configured via the /etc/exports file.
10 # probe: true
11 # config: /etc/sysconfig/nfsd
12
13 # Source function library.
14 . /etc/rc.d/init.d/functions
15
16 # Source networking configuration.
17 if [ ! -f /etc/sysconfig/network ]; then
18     exit 0
19 fi
20
21 . /etc/sysconfig/network
22
23 # Check that networking is up.
24 [ ${NETWORKING} = "no" ] && exit 0
25
26 [ -x /usr/sbin/rpc.nfsd ] || exit 0
27 [ -x /usr/sbin/rpc.mountd ] || exit 0
28 [ -x /usr/sbin/exportfs ] || exit 0
29 [ -s /etc/exports ] || exit 0
30
31 # Check for and source configuration file otherwise set defaults
32 # TUNE_QUEUE: controls whether to up the size of input queues
33 NFSDCFG=/etc/sysconfig/nfsd
34 if [ -f "$NFSDCFG" ]; then
35    # Tune nfs server settings
36    . "$NFSDCFG"
37 else
38    # Set some defaults
39    TUNE_QUEUE ="no"
40    # Default to NFS version 3.
41    RPCMOUNTDOPTS=""
42 fi
43
44 # Number of servers to be started by default
45 [ -z "$RPCNFSDCOUNT" ] && RPCNFSDCOUNT=8
46
47 # Remote quota server
48 [ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
49
50 # Get the initial values for the input sock queues
51 # at the time of running the script.
52 if [ "$TUNE_QUEUE" = "yes" ]; then
53     RMEM_DEFAULT=`/sbin/sysctl -n net.core.rmem_default`
54     RMEM_MAX=`/sbin/sysctl -n net.core.rmem_max`
55     WMEM_DEFAULT=`/sbin/sysctl -n net.core.wmem_default`
56     WMEM_MAX=`/sbin/sysctl -n net.core.wmem_max`
57     # 256kb recommended minimum size based on SPECsfs NFS benchmarks
58     [ -z "$NFS_QS" ] && NFS_QS=262144
59 fi
60
61 # See how we were called.
62 case "$1" in
63   start)
64         # Start daemons.
65         # Apply input queue increase for nfs server
66         if [ "$TUNE_QUEUE" = "yes" ]; then
67             /sbin/sysctl -w net.core.rmem_default=$NFSD_QS >/dev/null 2>&1
68             /sbin/sysctl -w net.core.rmem_max=$NFSD_QS >/dev/null 2>&1
69             /sbin/sysctl -w net.core.wmem_default=$NFSD_QS >/dev/null 2>&1
70             /sbin/sysctl -w net.core.wmem_max=$NFSD_QS >/dev/null 2>&1
71         fi
72         action "Starting NFS services: " /usr/sbin/exportfs -r
73         if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
74             echo -n "Starting NFS quotas: "
75             daemon rpc.rquotad
76             echo
77         fi
78         echo -n "Starting NFS daemon: "
79         daemon rpc.nfsd $RPCNFSDCOUNT
80         echo
81
82         if [ -z "$RPCMOUNTDOPTS" ]; then
83             # Let's see if we support NFS version 3.
84             /usr/sbin/rpcinfo -u localhost nfs 3 &>/dev/null
85             if [ $? -ne 0 ]; then
86                 RPCMOUNTDOPTS="--no-nfs-version 3"
87             fi
88         fi
89
90         echo -n "Starting NFS mountd: "
91         daemon rpc.mountd $RPCMOUNTDOPTS
92         echo
93         touch /var/lock/subsys/nfs
94         # reset input queue for rest of network services
95         if [ "$TUNE_QUEUE" = "yes" ]; then
96             /sbin/sysctl -w net.core.rmem_default=$RMEM_DEFAULT >/dev/null 2>&1
97             /sbin/sysctl -w net.core.rmem_max=$RMEM_MAX >/dev/null 2>&1
98             /sbin/sysctl -w net.core.wmem_default=$WMEM_DEFAULT >/dev/null 2>&1
99             /sbin/sysctl -w net.core.wmem_max=$WMEM_MAX >/dev/null 2>&1
100         fi
101         ;;
102   stop)
103         # Stop daemons.
104         echo -n "Shutting down NFS mountd: "
105         killproc rpc.mountd
106         echo
107         echo -n "Shutting down NFS daemon: "
108         killproc nfsd
109         echo
110         if [ -n "$RQUOTAD" ]; then
111                 echo -n "Shutting down NFS quotas: "
112                 killproc rpc.rquotad
113                 echo
114         fi
115         # Do it the last so that clients can still access the server
116         # when the server is running.
117         action "Shutting down NFS services: " /usr/sbin/exportfs -au
118         rm -f /var/lock/subsys/nfs
119         ;;
120   status)
121         status rpc.mountd
122         status nfsd
123         if [ -n "$RQUOTAD" ]; then
124                 status rpc.rquotad
125         fi
126         ;;
127   restart)
128         $0 stop
129         $0 start
130         ;;
131   reload)
132         /usr/sbin/exportfs -r
133         touch /var/lock/subsys/nfs
134         ;;
135   probe)
136         if [ ! -f /var/lock/subsys/nfs ] ; then
137           echo start; exit 0
138         fi
139         /sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
140         /sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
141         if [ $MOUNTD = 1 -o $NFSD = 1 ] ; then
142           echo restart; exit 0
143         fi
144         if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
145           echo reload; exit 0
146         fi
147         ;;
148   *)
149         echo "Usage: nfs {start|stop|status|restart|reload}"
150         exit 1
151 esac
152
153 exit 0