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