3 # nfs This shell script takes care of starting and stopping
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.
11 # config: /etc/sysconfig/nfs
13 # Source function library.
14 . /etc/rc.d/init.d/functions
16 # Source networking configuration.
17 if [ ! -f /etc/sysconfig/network ]; then
21 . /etc/sysconfig/network
23 # Check that networking is up.
24 [ ${NETWORKING} = "no" ] && exit 0
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
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
35 [ -z "$MOUNTD_NFS_V2" ] && MOUNTD_NFS_V2=auto
36 [ -z "$MOUNTD_NFS_V3" ] && MOUNTD_NFS_V3=auto
38 # Number of servers to be started by default
39 [ -z "$NFSDCOUNT" ] && NFSDCOUNT=8
42 [ -z "$RQUOTAD" ] && RQUOTAD=`type -path rpc.rquotad`
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
53 # See how we were called.
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
62 action "Starting NFS services: " /usr/sbin/exportfs -r
63 if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
64 echo -n "Starting NFS quotas: "
68 echo -n "Starting NFS daemon: "
69 daemon rpc.nfsd $NFSDCOUNT
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"
77 case $MOUNTD_NFS_V2 in
79 # Let's see if we support NFS version 2.
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
85 echo nfsd 127.0.0.1 2147483647 localhost > /proc/net/rpc/auth.unix.ip/channel
89 /usr/sbin/rpcinfo -u localhost nfs 2 &>/dev/null
91 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 2"
93 if [ -n "$ClearAddr" ]; then
94 echo nfsd 127.0.0.1 1 > /proc/net/rpc/auth.unix.ip/channel
98 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 2"
101 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --nfs-version 2"
105 case $MOUNTD_NFS_V3 in
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"
114 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 3"
117 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --nfs-version 3"
121 echo -n "Starting NFS mountd: "
122 daemon rpc.mountd $MOUNTD_OPTIONS
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
133 echo -n "Shutting down NFS mountd: "
136 echo -n "Shutting down NFS daemon: "
139 if [ -n "$RQUOTAD" ]; then
140 echo -n "Shutting down NFS quotas: "
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
152 if [ -n "$RQUOTAD" ]; then
161 /usr/sbin/exportfs -r
162 touch /var/lock/subsys/nfs
165 if [ ! -f /var/lock/subsys/nfs ] ; then
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
173 if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
178 echo "Usage: nfs {start|stop|status|restart|reload}"