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
25 DEFAULTFILE=/etc/default/nfs-kernel-server
28 if [ -f $DEFAULTFILE ]; then
32 # See how we were called.
35 cd / # daemons should have root dir as cwd
36 if grep -q '^/' /etc/exports
38 printf "Exporting directories for $DESC..."
39 $PREFIX/sbin/exportfs -r
42 printf "Starting $DESC:"
44 start-stop-daemon --start --quiet \
45 --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT
49 # make sure 127.0.0.1 is a valid source for requests
51 if [ -f /proc/net/rpc/auth.unix.ip/channel ]
53 fgrep -qs 127.0.0.1 /proc/net/rpc/auth.unix.ip/content || {
54 echo "nfsd 127.0.0.1 2147483647 localhost" >/proc/net/rpc/auth.unix.ip/channel
59 $PREFIX/bin/rpcinfo -u localhost nfs 3 >/dev/null 2>&1 ||
60 RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
62 [ -z "$ClearAddr" ] || echo "nfsd 127.0.0.1 1" >/proc/net/rpc/auth.unix.ip/channel
64 start-stop-daemon --start --quiet \
65 --exec $PREFIX/sbin/rpc.mountd -- $RPCMOUNTDOPTS
68 echo "Not starting $DESC: No exports."
73 printf "Stopping $DESC: mountd"
74 start-stop-daemon --stop --oknodo --quiet \
75 --name rpc.mountd --user 0
77 start-stop-daemon --stop --oknodo --quiet \
78 --name nfsd --user 0 --signal 2
81 printf "Unexporting directories for $DESC..."
82 $PREFIX/sbin/exportfs -au
86 reload | force-reload)
87 printf "Re-exporting directories for $DESC..."
88 $PREFIX/sbin/exportfs -r
99 echo "Usage: nfs-kernel-server {start|stop|reload|force-reload|restart}"