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
54 # See how we were called.
57 if [ -d /proc/fs/nfsd -a "$MOUNT_NFSD" = "yes" ] ; then
58 /bin/mount -t nfsd nfsd /proc/fs/nfsd
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
66 action "Starting NFS services: " /usr/sbin/exportfs -r
67 if [ -n "$RQUOTAD" -a "$RQUOTAD" != "no" ]; then
68 echo -n "Starting NFS quotas: "
72 echo -n "Starting NFS daemon: "
73 daemon rpc.nfsd $NFSDCOUNT
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"
81 case $MOUNTD_NFS_V2 in
83 # Let's see if we support NFS version 2.
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
89 echo nfsd 127.0.0.1 2147483647 localhost > /proc/net/rpc/auth.unix.ip/channel
93 /usr/sbin/rpcinfo -u localhost nfs 2 &>/dev/null
95 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 2"
97 if [ -n "$ClearAddr" ]; then
98 echo nfsd 127.0.0.1 1 > /proc/net/rpc/auth.unix.ip/channel
102 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 2"
105 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --nfs-version 2"
109 case $MOUNTD_NFS_V3 in
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"
118 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --no-nfs-version 3"
121 MOUNTD_OPTIONS="$MOUNTD_OPTIONS --nfs-version 3"
125 echo -n "Starting NFS mountd: "
126 daemon rpc.mountd $MOUNTD_OPTIONS
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
137 echo -n "Shutting down NFS mountd: "
140 echo -n "Shutting down NFS daemon: "
143 if [ -n "$RQUOTAD" ]; then
144 echo -n "Shutting down NFS quotas: "
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
154 rm -f /var/lock/subsys/nfs
159 if [ -n "$RQUOTAD" ]; then
168 /usr/sbin/exportfs -r
169 touch /var/lock/subsys/nfs
172 if [ ! -f /var/lock/subsys/nfs ] ; then
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
180 if [ /etc/exports -nt /var/lock/subsys/nfs ] ; then
185 echo "Usage: nfs {start|stop|status|restart|reload}"