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
32 PROCNFSD_MOUNTPOINT=/proc/fs/nfsd
33 if [ -f $DEFAULTFILE ]; then
38 modprobe -q "$1" || true
42 if ! grep -E -qs "$1\$" /proc/filesystems
46 if ! mountpoint -q "$2"
48 mount -t "$1" "$1" "$2"
54 # See how we were called.
57 cd / # daemons should have root dir as cwd
58 # FIXME if grep -q '^/' /etc/exports
59 if [ -f /etc/exports ]
62 do_mount nfsd $PROCNFSD_MOUNTPOINT || NEED_SVCGSSD=no
63 printf "Exporting directories for $DESC..."
64 $PREFIX/sbin/exportfs -r
67 printf "Starting $DESC:"
68 if [ "$NEED_SVCGSSD" = yes ]
71 start-stop-daemon --start --quiet \
72 --make-pidfile --pidfile /run/rpc.svcgssd.pid \
73 --exec $PREFIX/sbin/rpc.svcgssd -- $RPCSVCGSSDOPTS
77 start-stop-daemon --start --quiet \
78 --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT
82 # make sure 127.0.0.1 is a valid source for requests
84 if [ -f /proc/net/rpc/auth.unix.ip/channel ]
86 fgrep -qs 127.0.0.1 /proc/net/rpc/auth.unix.ip/content || {
87 echo "nfsd 127.0.0.1 2147483647 localhost" >/proc/net/rpc/auth.unix.ip/channel
92 [ -z "$ClearAddr" ] || echo "nfsd 127.0.0.1 1" >/proc/net/rpc/auth.unix.ip/channel
94 start-stop-daemon --start --quiet \
95 --exec $PREFIX/sbin/rpc.mountd -- $RPCMOUNTDOPTS
98 echo "Not starting $DESC: No exports."
103 printf "Stopping $DESC: mountd"
104 start-stop-daemon --stop --oknodo --quiet \
105 --name rpc.mountd --user 0
106 if [ "$NEED_SVCGSSD" = yes ]
109 start-stop-daemon --stop --oknodo --quiet \
110 --name rpc.svcgssd --user 0
111 rm -f /run/rpc.svcgssd.pid
114 start-stop-daemon --stop --oknodo --quiet \
115 --name nfsd --user 0 --signal 2
118 printf "Unexporting directories for $DESC..."
119 $PREFIX/sbin/exportfs -au
123 reload | force-reload)
124 printf "Re-exporting directories for $DESC..."
125 $PREFIX/sbin/exportfs -r
136 echo "Usage: nfs-kernel-server {start|stop|reload|force-reload|restart}"