Imported Debian patch 1.0.7-5
[nfs-utils.git] / debian / nfs-common.init
1 #!/bin/sh
2 #
3 # nfs-common    This shell script takes care of starting and stopping
4 #               common daemons required for NFS clients and servers.
5 #
6 # chkconfig: 345 20 80
7 # description: NFS is a popular protocol for file sharing across \
8 #              TCP/IP networks. This service provides NFS file \
9 #              locking functionality.
10 #
11
12 set -e
13
14 # What is this?
15 DESC="NFS common utilities"
16
17 # Read config
18 DEFAULTFILE=/etc/default/nfs-common
19 PREFIX=
20 NEED_LOCKD=
21 NEED_IDMAPD=yes
22 IDMAPD_PIDFILE=/var/run/rpc.idmapd.pid
23 NEED_GSSD=yes
24 GSSD_PIDFILE=/var/run/rpc.gssd.pid
25 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
26 RPCGSSDOPTS=
27 if [ -f $DEFAULTFILE ]; then
28     . $DEFAULTFILE
29 fi
30
31 # Determine whether lockd daemon is required.
32 case "$NEED_LOCKD" in
33 yes|no) ;;
34 *)  case `uname -r` in
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.)
39         NEED_LOCKD=yes
40         if test -f /proc/ksyms
41         then
42             grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
43         fi
44         ;;
45
46     *)  # Modern kernels (>= 2.4) start a lockd thread automatically.
47         NEED_LOCKD=no
48         ;;
49     esac
50     ;;
51 esac
52
53 # Exit if required binaries are missing.
54 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
55 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD"  = no ] || exit 0
56 [ -x /usr/sbin/rpc.idmapd   ] || [ "$NEED_IDMAPD" = no ] || exit 0
57 [ -x /usr/sbin/rpc.gssd     ] || [ "$NEED_GSSD"   = no ] || exit 0
58
59 do_modprobe() {
60     modprobe -q "$1" || true
61 }
62
63 do_mount() {
64     if ! grep -E -qs "$1\$" /proc/filesystems
65     then
66         return 1
67     fi
68     if ! mountpoint -q "$2"
69     then
70         mount -t "$1" "$1" "$2"
71         return
72     fi
73     return 0
74 }
75
76 # See how we were called.
77 case "$1" in
78   start)
79         cd /    # daemons should have root dir as cwd
80         printf "Starting $DESC:"
81         printf " statd"
82         start-stop-daemon --start --quiet \
83             --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
84         if [ "$NEED_LOCKD" = yes ]
85         then
86             printf " lockd"
87             start-stop-daemon --start --quiet \
88                 --exec $PREFIX/sbin/rpc.lockd  || true
89         fi
90         if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
91         then
92             do_modprobe nfs
93             if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
94             then
95                 if [ "$NEED_IDMAPD" = yes ]
96                 then
97                     printf " idmapd"
98                     start-stop-daemon --start --quiet \
99                             --make-pidfile --pidfile $IDMAPD_PIDFILE \
100                             --exec /usr/sbin/rpc.idmapd
101                 fi
102                 if [ "$NEED_GSSD" = yes ]
103                 then
104                     printf " gssd"
105                     start-stop-daemon --start --quiet \
106                             --make-pidfile --pidfile $GSSD_PIDFILE \
107                             --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
108                 fi
109             fi
110         fi
111         echo "."
112         ;;
113
114   stop)
115         printf "Stopping $DESC:"
116         if [ "$NEED_GSSD" = yes ]
117         then
118             printf " gssd"
119             start-stop-daemon --stop --oknodo --quiet \
120                     --name rpc.gssd
121             rm -f $GSSD_PIDFILE
122         fi
123         if [ "$NEED_IDMAPD" = yes ]
124         then
125             printf " idmapd"
126             start-stop-daemon --stop --oknodo --quiet \
127                 --name rpc.idmapd
128             rm -f $IDMAPD_PIDFILE
129         fi
130         if [ "$NEED_LOCKD" = yes ]
131         then
132             printf " lockd"
133             start-stop-daemon --stop --oknodo --quiet \
134                 --name rpc.lockd || true
135         else
136             pkill -KILL -u root -x lockd || true
137         fi
138         printf " statd"
139         start-stop-daemon --stop --oknodo --quiet \
140             --name rpc.statd
141         echo "."
142         ;;
143
144   restart | force-reload)
145         $0 stop
146         sleep 1
147         $0 start
148         ;;
149
150   *)
151         echo "Usage: nfs-common {start|stop|restart}"
152         exit 1
153         ;;
154 esac
155
156 exit 0