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.
13 DESC="NFS common utilities"
16 DEFAULTFILE=/etc/default/nfs-common
20 IDMAPD_PIDFILE=/var/run/rpc.idmapd.pid
22 GSSD_PIDFILE=/var/run/rpc.gssd.pid
23 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
25 if [ -f $DEFAULTFILE ]; then
29 . /lib/lsb/init-functions
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"
117 if mountpoint -q "$1"
124 # See how we were called.
127 log_daemon_msg "Starting $DESC"
129 log_progress_msg "statd"
130 start-stop-daemon --start --oknodo --quiet \
131 --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
137 if [ "$NEED_LOCKD" = yes ]
139 log_progress_msg "lockd"
140 start-stop-daemon --start --oknodo --quiet \
141 --exec $PREFIX/sbin/rpc.lockd
147 if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
151 if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
153 if [ "$NEED_IDMAPD" = yes ]
155 log_progress_msg "idmapd"
156 start-stop-daemon --start --oknodo --quiet \
157 --make-pidfile --pidfile $IDMAPD_PIDFILE \
158 --exec /usr/sbin/rpc.idmapd
164 if [ "$NEED_GSSD" = yes ]
166 do_modprobe rpcsec_gss_krb5
167 log_progress_msg "gssd"
168 start-stop-daemon --start --oknodo --quiet \
169 --make-pidfile --pidfile $GSSD_PIDFILE \
170 --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
182 log_daemon_msg "Stopping $DESC"
184 if [ "$NEED_GSSD" = yes ]
186 log_progress_msg "gssd"
187 start-stop-daemon --stop --oknodo --quiet \
195 if [ "$NEED_IDMAPD" = yes ]
197 log_progress_msg "idmapd"
198 start-stop-daemon --stop --oknodo --quiet \
204 rm -f $IDMAPD_PIDFILE
206 if [ "$NEED_LOCKD" = yes ]
208 log_progress_msg "lockd"
209 start-stop-daemon --stop --oknodo --quiet \
216 pkill -KILL -u root -x lockd || true
218 log_progress_msg "statd"
219 start-stop-daemon --stop --oknodo --quiet \
225 do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
230 if ! pidof rpc.statd >/dev/null
232 echo "rpc.statd not running"
236 if [ "$NEED_GSSD" = yes ]
238 if [ ! -f "$GSSD_PIDFILE" ] || ! pidof rpc.gssd >/dev/null
240 echo "rpc.statd running, but rpc.gssd halted"
245 if [ "$NEED_LOCKD" = yes ]
247 if ! pidof rpc.lockd >/dev/null
249 echo "rpc.statd running, but rpc.lockd halted"
254 if [ "$NEED_IDMAPD" = yes ]
256 if [ ! -f "$IDMAPD_PIDFILE" ] || ! pidof rpc.idmapd >/dev/null
258 echo "rpc.statd running, but rpc.idmapd halted"
263 echo "rpc.statd running"
267 restart | force-reload)
274 log_success_msg "Usage: nfs-common {start|stop|status|restart}"