3 # nfs-common This shell script takes care of starting and stopping
4 # common daemons required for NFS clients and servers.
7 # description: NFS is a popular protocol for file sharing across \
8 # TCP/IP networks. This service provides NFS file \
9 # locking functionality.
15 DESC="NFS common utilities"
18 DEFAULTFILE=/etc/default/nfs-common
22 IDMAPD_PIDFILE=/var/run/rpc.idmapd.pid
24 GSSD_PIDFILE=/var/run/rpc.gssd.pid
25 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
27 if [ -f $DEFAULTFILE ]; then
31 # Determine whether lockd daemon is required.
35 '' | [01].* | 2.[0123].* )
36 # Older kernels may or may not need a lockd daemon.
37 # We must assume they do, unless we can prove otherwise.
38 # (A false positive here results only in a harmless message.)
40 if test -f /proc/ksyms
42 grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
46 *) # Modern kernels (>= 2.4) start a lockd thread automatically.
54 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
55 # /etc/defaults settings, if any, will override our autodetection.) This code
56 # is partially adapted from the mountnfs.sh script in the sysvinit package.
63 while read DEV MTPT FSTYPE OPTS REST
65 if [ "$FSTYPE" = "nfs4" ]; then
69 sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
77 case "$NEED_IDMAPD" in
81 NEED_IDMAPD=$AUTO_NEED_IDMAPD
89 NEED_GSSD=$AUTO_NEED_GSSD
93 # Exit if required binaries are missing.
94 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
95 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD" = no ] || exit 0
96 [ -x /usr/sbin/rpc.idmapd ] || [ "$NEED_IDMAPD" = no ] || exit 0
97 [ -x /usr/sbin/rpc.gssd ] || [ "$NEED_GSSD" = no ] || exit 0
100 modprobe -q "$1" || true
104 if ! grep -E -qs "$1\$" /proc/filesystems
108 if ! mountpoint -q "$2"
110 mount -t "$1" "$1" "$2"
116 # See how we were called.
119 cd / # daemons should have root dir as cwd
120 printf "Starting $DESC:"
122 start-stop-daemon --start --quiet \
123 --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
124 if [ "$NEED_LOCKD" = yes ]
127 start-stop-daemon --start --quiet \
128 --exec $PREFIX/sbin/rpc.lockd || true
130 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
134 if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
136 if [ "$NEED_IDMAPD" = yes ]
139 start-stop-daemon --start --quiet \
140 --make-pidfile --pidfile $IDMAPD_PIDFILE \
141 --exec /usr/sbin/rpc.idmapd
143 if [ "$NEED_GSSD" = yes ]
145 do_modprobe rpcsec_gss_krb5
147 start-stop-daemon --start --quiet \
148 --make-pidfile --pidfile $GSSD_PIDFILE \
149 --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
157 printf "Stopping $DESC:"
158 if [ "$NEED_GSSD" = yes ]
161 start-stop-daemon --stop --oknodo --quiet \
165 if [ "$NEED_IDMAPD" = yes ]
168 start-stop-daemon --stop --oknodo --quiet \
170 rm -f $IDMAPD_PIDFILE
172 if [ "$NEED_LOCKD" = yes ]
175 start-stop-daemon --stop --oknodo --quiet \
176 --name rpc.lockd || true
178 pkill -KILL -u root -x lockd || true
181 start-stop-daemon --stop --oknodo --quiet \
186 restart | force-reload)
193 echo "Usage: nfs-common {start|stop|restart}"