4 # This shell script takes care of starting and stopping
5 # the kernel-mode NFS server.
8 # description: NFS is a popular protocol for file sharing across TCP/IP \
9 # networks. This service provides NFS server functionality, \
10 # which is configured via the /etc/exports file.
16 DESC="NFS kernel daemon"
19 # Exit if required binaries are missing.
20 [ -x $PREFIX/sbin/rpc.nfsd ] || exit 0
21 [ -x $PREFIX/sbin/rpc.mountd ] || exit 0
22 [ -x $PREFIX/sbin/exportfs ] || exit 0
23 [ -x $PREFIX/sbin/rpc.svcgssd ] || exit 0
26 DEFAULTFILE=/etc/default/nfs-kernel-server
33 PROCNFSD_MOUNTPOINT=/proc/fs/nfsd
34 if [ -f $DEFAULTFILE ]; then
39 if [ -x /sbin/modprobe ]
41 modprobe -q "$1" || true
46 if ! grep -E -qs "$1\$" /proc/filesystems
50 if ! mountpoint -q "$2"
52 mount -t "$1" "$1" "$2"
58 # See how we were called.
61 cd / # daemons should have root dir as cwd
62 if [ -f /etc/exports ]
65 do_mount nfsd $PROCNFSD_MOUNTPOINT || NEED_SVCGSSD=no
66 printf "Exporting directories for $DESC..."
67 $PREFIX/sbin/exportfs -r
70 printf "Starting $DESC:"
71 if [ "$NEED_SVCGSSD" = yes ]
74 start-stop-daemon --start --quiet \
75 --make-pidfile --pidfile /var/run/rpc.svcgssd.pid \
76 --exec $PREFIX/sbin/rpc.svcgssd -- $RPCSVCGSSDOPTS
80 start-stop-daemon --start --quiet \
81 --nicelevel $RPCNFSDPRIORITY \
82 --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT
86 # make sure 127.0.0.1 is a valid source for requests
88 if [ -f /proc/net/rpc/auth.unix.ip/channel ]
90 fgrep -qs 127.0.0.1 /proc/net/rpc/auth.unix.ip/content || {
91 echo "nfsd 127.0.0.1 2147483647 localhost" >/proc/net/rpc/auth.unix.ip/channel
96 $PREFIX/bin/rpcinfo -u localhost nfs 3 >/dev/null 2>&1 ||
97 RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
99 [ -z "$ClearAddr" ] || echo "nfsd 127.0.0.1 1" >/proc/net/rpc/auth.unix.ip/channel
101 start-stop-daemon --start --quiet \
102 --exec $PREFIX/sbin/rpc.mountd -- $RPCMOUNTDOPTS
105 echo "Not starting $DESC: No exports."
110 printf "Stopping $DESC: mountd"
111 start-stop-daemon --stop --oknodo --quiet \
112 --name rpc.mountd --user 0
113 if [ "$NEED_SVCGSSD" = yes ]
116 start-stop-daemon --stop --oknodo --quiet \
117 --name rpc.svcgssd --user 0
118 rm -f /var/run/rpc.svcgssd.pid
121 start-stop-daemon --stop --oknodo --quiet \
122 --name nfsd --user 0 --signal 2
125 printf "Unexporting directories for $DESC..."
126 $PREFIX/sbin/exportfs -au
127 if mountpoint -q /proc/nfs/nfsd
129 $PREFIX/sbin/exportfs -f
134 reload | force-reload)
135 printf "Re-exporting directories for $DESC..."
136 $PREFIX/sbin/exportfs -r
147 echo "Usage: nfs-kernel-server {start|stop|reload|force-reload|restart}"