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.
14 DESC="NFS kernel daemon"
17 # Exit if required binaries are missing.
18 [ -x $PREFIX/sbin/rpc.nfsd ] || exit 0
19 [ -x $PREFIX/sbin/rpc.mountd ] || exit 0
20 [ -x $PREFIX/sbin/exportfs ] || exit 0
23 DEFAULTFILE=/etc/default/nfs-kernel-server
30 PROCNFSD_MOUNTPOINT=/proc/fs/nfsd
31 if [ -f $DEFAULTFILE ]; then
35 . /lib/lsb/init-functions
38 if [ -x /sbin/modprobe ]
40 modprobe -q "$1" || true
45 if ! grep -E -qs "$1\$" /proc/filesystems
49 if ! mountpoint -q "$2"
51 mount -t "$1" "$1" "$2"
57 # See how we were called.
60 if [ -f /etc/exports ]
64 # See if our running kernel supports the NFS kernel server
65 if [ -f /proc/kallsyms ] && ! grep -qE 'init_nf(sd| )' /proc/kallsyms; then
66 log_warning_msg "Not starting $DESC: no support in current kernel."
70 do_mount nfsd $PROCNFSD_MOUNTPOINT || NEED_SVCGSSD=no
71 log_begin_msg "Exporting directories for $DESC..."
72 $PREFIX/sbin/exportfs -r
79 log_daemon_msg "Starting $DESC"
80 log_progress_msg "nfsd"
81 start-stop-daemon --start --oknodo --quiet \
82 --nicelevel $RPCNFSDPRIORITY \
83 --exec $PREFIX/sbin/rpc.nfsd -- $RPCNFSDCOUNT
89 # make sure 127.0.0.1 is a valid source for requests
91 if [ -f /proc/net/rpc/auth.unix.ip/channel ]
93 fgrep -qs 127.0.0.1 /proc/net/rpc/auth.unix.ip/content || {
94 echo "nfsd 127.0.0.1 2147483647 localhost" >/proc/net/rpc/auth.unix.ip/channel
99 $PREFIX/bin/rpcinfo -u localhost nfs 3 >/dev/null 2>&1 ||
100 RPCMOUNTDOPTS="$RPCMOUNTDOPTS --no-nfs-version 3"
102 [ -z "$ClearAddr" ] || echo "nfsd 127.0.0.1 1" >/proc/net/rpc/auth.unix.ip/channel
104 log_progress_msg "mountd"
105 start-stop-daemon --start --oknodo --quiet \
106 --exec $PREFIX/sbin/rpc.mountd -- $RPCMOUNTDOPTS
114 log_warning_msg "Not starting $DESC: no exports."
119 log_daemon_msg "Stopping $DESC"
121 log_progress_msg "mountd"
122 start-stop-daemon --stop --oknodo --quiet \
123 --name rpc.mountd --user 0
129 log_progress_msg "nfsd"
130 start-stop-daemon --stop --oknodo --quiet \
131 --name nfsd --user 0 --signal 2
139 log_begin_msg "Unexporting directories for $DESC..."
140 $PREFIX/sbin/exportfs -au
147 if mountpoint -q /proc/nfs/nfsd
149 $PREFIX/sbin/exportfs -f
154 if pidof nfsd >/dev/null
159 echo "nfsd not running"
164 reload | force-reload)
165 log_begin_msg "Re-exporting directories for $DESC..."
166 $PREFIX/sbin/exportfs -r
178 log_success_msg "Usage: nfs-kernel-server {start|stop|status|reload|force-reload|restart}"