]> git.decadent.org.uk Git - nfs-utils.git/blob - etc/redhat/nfs.init
ac459379802faa22e38fbe3a7ee50a8fd5fadc2e
[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/nfs
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 [ -f /etc/sysconfig/nfs ] && . /etc/sysconfig/nfs
34
35 [ -z "$MOUNTD_NFS_V2" ] && MOUNTD_NFS_V2=auto
36 [ -z "$MOUNTD_NFS_V3" ] && MOUNTD_NFS_V3=auto
37
38 # Number of servers to be started by default
39 [ -z "$NFSDCOUNT" ] && NFSDCOUNT=8
40
41 # Remote quota server
42 [ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
43
44 # Get the initial values for the input sock queues
45 # at the time of running the script.
46 if [ "$TUNE_QUEUE" = "yes" ]; then
47     RMEM_DEFAULT=`/sbin/sysctl -n net.core.rmem_default`
48     RMEM_MAX=`/sbin/sysctl -n net.core.rmem_max`
49     # 256kb recommended minimum size based on SPECsfs NFS benchmarks
50     [ -z "$NFS_QS" ] && NFS_QS=262144
51 fi
52
53 # See how we were called.
54 case "$1" in
55   start)
56         # Start daemons.
57         # Apply input queue increase for nfs server
58         if [ "$TUNE_QUEUE" = "yes" ]; then
59             /sbin/sysctl -w net.core.rmem_default=$NFSD_QS >/dev/null 2>&1
60             /sbin/sysctl -w net.core.rmem_max=$NFSD_QS >/dev/null 2>&1
61         fi
62         action "Starting NFS services: " /usr/sbin/exportfs -r
63         if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
64             echo -n "Starting NFS quotas: "
65             daemon rpc.rquotad
66             echo
67         fi
68         echo -n "Starting NFS daemon: "
69         daemon rpc.nfsd $NFSDCOUNT
70         echo
71
72         [ -n "$MOUNTD_PORT" ] \
73         && MOUNTD_OPTIONS="$MOUNTD_OPTIONS -p $MOUNTD_PORT"
74         [ "$MOUNTD_TCP" = "no" -o "$MOUNTD_TCP" = "NO" ] \
75         && MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-tcp"
76
77         case $MOUNTD_NFS_V2 in
78         auto|AUTO)
79             # Let's see if we support NFS version 2.
80             ClearAddr=
81             if [ -f /proc/net/rpc/auth.unix.ip/channel ] ; then
82                if   grep -s 127.0.0.1 /proc/net/rpc/auth.unix.ip/content > /dev/null ; then
83                     : address already known
84                else
85                     echo nfsd 127.0.0.1 2147483647 localhost > /proc/net/rpc/auth.unix.ip/channel
86                     ClearAddr=yes
87               fi
88             fi
89             /usr/sbin/rpcinfo -u localhost nfs 2 &>/dev/null
90             if [ $? -ne 0 ]; then
91                 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 2"
92             fi
93             if [ -n "$ClearAddr" ]; then
94                   echo nfsd 127.0.0.1 1  > /proc/net/rpc/auth.unix.ip/channel
95             fi
96             ;;
97         no|NO)
98             MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 2"
99             ;;
100         yes|YES)
101             MOUNTD_OPTIONS="$MOUNTD_OPTIONS --nfs-version 2"
102             ;;
103         esac
104
105         case $MOUNTD_NFS_V3 in
106         auto|AUTO)
107             # Let's see if we support NFS version 3.
108             /usr/sbin/rpcinfo -u localhost nfs 3 &>/dev/null
109             if [ $? -ne 0 ]; then
110                 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 3"
111             fi
112             ;;
113         no|NO)
114             MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 3"
115             ;;
116         yes|YES)
117             MOUNTD_OPTIONS="$MOUNTD_OPTIONS --nfs-version 3"
118             ;;
119         esac
120
121         echo -n "Starting NFS mountd: "
122         daemon rpc.mountd $MOUNTD_OPTIONS
123         echo
124         touch /var/lock/subsys/nfs
125         # reset input queue for rest of network services
126         if [ "$TUNE_QUEUE" = "yes" ]; then
127             /sbin/sysctl -w net.core.rmem_default=$RMEM_DEFAULT >/dev/null 2>&1
128             /sbin/sysctl -w net.core.rmem_max=$RMEM_MAX >/dev/null 2>&1
129         fi
130         ;;
131   stop)
132         # Stop daemons.
133         echo -n "Shutting down NFS mountd: "
134         killproc rpc.mountd
135         echo
136         echo -n "Shutting down NFS daemon: "
137         killproc nfsd
138         echo
139         if [ -n "$RQUOTAD" ]; then
140                 echo -n "Shutting down NFS quotas: "
141                 killproc rpc.rquotad
142                 echo
143         fi
144         # Do it the last so that clients can still access the server
145         # when the server is running.
146         action "Shutting down NFS services: " /usr/sbin/exportfs -au
147         rm -f /var/lock/subsys/nfs
148         ;;
149   status)
150         status rpc.mountd
151         status nfsd
152         if [ -n "$RQUOTAD" ]; then
153                 status rpc.rquotad
154         fi
155         ;;
156   restart)
157         $0 stop
158         $0 start
159         ;;
160   reload)
161         /usr/sbin/exportfs -r
162         touch /var/lock/subsys/nfs
163         ;;
164   probe)
165         if [ ! -f /var/lock/subsys/nfs ] ; then
166           echo start; exit 0
167         fi
168         /sbin/pidof rpc.mountd >/dev/null 2>&1; MOUNTD="$?"
169         /sbin/pidof nfsd >/dev/null 2>&1; NFSD="$?"
170         if [ $MOUNTD = 1 -o $NFSD = 1 ] ; then
171           echo restart; exit 0
172         fi
173         if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
174           echo reload; exit 0
175         fi
176         ;;
177   *)
178         echo "Usage: nfs {start|stop|status|restart|reload}"
179         exit 1
180 esac
181
182 exit 0