5 # Required-Start: $time
7 # Default-Start: 2 3 4 5
9 # Short-Description: NFS support files common to client and server
10 # Description: NFS is a popular protocol for file sharing across
11 # TCP/IP networks. This service provides various
12 # support functions for NFS mounts.
16 DESC="NFS common utilities"
19 DEFAULTFILE=/etc/default/nfs-common
24 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
26 if [ -f $DEFAULTFILE ]; then
30 . /lib/lsb/init-functions
32 # Determine whether lockd daemon is required.
36 '' | [01].* | 2.[0123].* )
37 # Older kernels may or may not need a lockd daemon.
38 # We must assume they do, unless we can prove otherwise.
39 # (A false positive here results only in a harmless message.)
41 if test -f /proc/ksyms
43 grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
47 *) # Modern kernels (>= 2.4) start a lockd thread automatically.
55 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
56 # /etc/defaults settings, if any, will override our autodetection.) This code
57 # is partially adapted from the mountnfs.sh script in the sysvinit package.
64 while read DEV MTPT FSTYPE OPTS REST
66 if [ "$FSTYPE" = "nfs4" ]; then
70 sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
79 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
80 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
81 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
82 # file. This does not mean that there are NFSv4 or other mounts active (or
83 # even that nfs-kernel-server is installed), but it matches what the "start"
84 # condition in nfs-kernel-server's init script does, which has a value in
87 if [ -f /etc/exports ]; then
92 case "$NEED_IDMAPD" in
96 NEED_IDMAPD=$AUTO_NEED_IDMAPD
104 NEED_GSSD=$AUTO_NEED_GSSD
108 # Exit if required binaries are missing.
109 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
110 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD" = no ] || exit 0
111 [ -x /usr/sbin/rpc.idmapd ] || [ "$NEED_IDMAPD" = no ] || exit 0
112 [ -x /usr/sbin/rpc.gssd ] || [ "$NEED_GSSD" = no ] || exit 0
115 if [ -x /sbin/modprobe -a -f /proc/modules ]
117 modprobe -q "$1" || true
122 if ! grep -E -qs "$1\$" /proc/filesystems
126 if ! mountpoint -q "$2"
128 mount -t "$1" "$1" "$2"
135 if mountpoint -q "$1"
142 # See how we were called.
145 log_daemon_msg "Starting $DESC"
147 log_progress_msg "statd"
148 start-stop-daemon --start --oknodo --quiet \
149 --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
155 if [ "$NEED_LOCKD" = yes ]
157 log_progress_msg "lockd"
158 start-stop-daemon --start --oknodo --quiet \
159 --exec $PREFIX/sbin/rpc.lockd
165 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
169 if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
171 if [ "$NEED_IDMAPD" = yes ]
173 log_progress_msg "idmapd"
174 start-stop-daemon --start --oknodo --quiet \
175 --exec /usr/sbin/rpc.idmapd
181 if [ "$NEED_GSSD" = yes ]
183 do_modprobe rpcsec_gss_krb5
184 log_progress_msg "gssd"
186 # we need this available; better to fail now than
187 # mysteriously on the first mount
188 if ! grep -q -E '^nfs[ ]' /etc/services; then
189 log_action_end_msg 1 "broken /etc/services, please see /usr/share/doc/nfs-common/README.Debian.nfsv4"
193 start-stop-daemon --start --oknodo --quiet \
194 --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
206 log_daemon_msg "Stopping $DESC"
208 if [ "$NEED_GSSD" = yes ]
210 log_progress_msg "gssd"
211 start-stop-daemon --stop --oknodo --quiet \
218 if [ "$NEED_IDMAPD" = yes ]
220 log_progress_msg "idmapd"
221 start-stop-daemon --stop --oknodo --quiet \
228 if [ "$NEED_LOCKD" = yes ]
230 log_progress_msg "lockd"
231 start-stop-daemon --stop --oknodo --quiet \
238 pkill -KILL -u root -x lockd || true
240 log_progress_msg "statd"
241 start-stop-daemon --stop --oknodo --quiet \
247 do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
252 if ! pidof rpc.statd >/dev/null
254 echo "rpc.statd not running"
258 if [ "$NEED_GSSD" = yes ]
260 if ! pidof rpc.gssd >/dev/null
262 echo "rpc.statd running, but rpc.gssd halted"
267 if [ "$NEED_LOCKD" = yes ]
269 if ! pidof rpc.lockd >/dev/null
271 echo "rpc.statd running, but rpc.lockd halted"
276 if [ "$NEED_IDMAPD" = yes ]
278 if ! pidof rpc.idmapd >/dev/null
280 echo "rpc.statd running, but rpc.idmapd halted"
285 echo "rpc.statd running"
289 restart | force-reload)
296 log_success_msg "Usage: nfs-common {start|stop|status|restart}"