]> git.decadent.org.uk Git - nfs-utils.git/blob - debian/nfs-common.init
Imported Debian patch 1.0.9-6
[nfs-utils.git] / debian / nfs-common.init
1 #!/bin/sh
2
3 ### BEGIN INIT INFO
4 # Provides:          nfs-common
5 # Required-Start:    $time
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: NFS support files common to client and server
9 # Description:       NFS is a popular protocol for file sharing across
10 #                    TCP/IP networks. This service provides various
11 #                    support functions for NFS mounts.
12 ### END INIT INFO
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=
22 IDMAPD_PIDFILE=/var/run/rpc.idmapd.pid
23 NEED_GSSD=
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 . /lib/lsb/init-functions
32
33 # Determine whether lockd daemon is required.
34 case "$NEED_LOCKD" in
35 yes|no) ;;
36 *)  case `uname -r` in
37     '' | [01].* | 2.[0123].* )
38         # Older kernels may or may not need a lockd daemon.
39         # We must assume they do, unless we can prove otherwise.
40         # (A false positive here results only in a harmless message.)
41         NEED_LOCKD=yes
42         if test -f /proc/ksyms
43         then
44             grep -q lockdctl /proc/ksyms || NEED_LOCKD=no
45         fi
46         ;;
47
48     *)  # Modern kernels (>= 2.4) start a lockd thread automatically.
49         NEED_LOCKD=no
50         ;;
51     esac
52     ;;
53 esac
54
55 #
56 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
57 # /etc/defaults settings, if any, will override our autodetection.) This code
58 # is partially adapted from the mountnfs.sh script in the sysvinit package.
59 #
60 AUTO_NEED_IDMAPD=no
61 AUTO_NEED_GSSD=no
62
63 exec 9<&0 </etc/fstab
64
65 while read DEV MTPT FSTYPE OPTS REST
66 do
67     if [ "$FSTYPE" = "nfs4" ]; then
68         AUTO_NEED_IDMAPD=yes
69     fi
70     case "$OPTS" in
71         sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
72             AUTO_NEED_GSSD=yes
73         ;;
74     esac
75 done
76
77 exec 0<&9 9<&-
78
79 #
80 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
81 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
82 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
83 # file. This does not mean that there are NFSv4 or other mounts active (or
84 # even that nfs-kernel-server is installed), but it matches what the "start"
85 # condition in nfs-kernel-server's init script does, which has a value in
86 # itself.
87 #
88 if [ -f /etc/exports ]; then
89     AUTO_NEED_IDMAPD=yes
90 fi
91
92
93 case "$NEED_IDMAPD" in
94     yes|no)     
95         ;;
96     *)
97         NEED_IDMAPD=$AUTO_NEED_IDMAPD
98         ;;
99 esac
100
101 case "$NEED_GSSD" in
102     yes|no)     
103         ;;
104     *)
105         NEED_GSSD=$AUTO_NEED_GSSD
106         ;;
107 esac
108
109 # Exit if required binaries are missing.
110 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
111 [ -x $PREFIX/sbin/rpc.lockd ] || [ "$NEED_LOCKD"  = no ] || exit 0
112 [ -x /usr/sbin/rpc.idmapd   ] || [ "$NEED_IDMAPD" = no ] || exit 0
113 [ -x /usr/sbin/rpc.gssd     ] || [ "$NEED_GSSD"   = no ] || exit 0
114
115 do_modprobe() {
116     modprobe -q "$1" || true
117 }
118
119 do_mount() {
120     if ! grep -E -qs "$1\$" /proc/filesystems
121     then
122         return 1
123     fi
124     if ! mountpoint -q "$2"
125     then
126         mount -t "$1" "$1" "$2"
127         return
128     fi
129     return 0
130 }
131
132 do_umount() {
133     if mountpoint -q "$1"
134     then
135         umount "$1"
136     fi
137     return 0
138 }
139
140 # See how we were called.
141 case "$1" in
142   start)
143         log_daemon_msg "Starting $DESC"
144
145         log_progress_msg "statd"
146         start-stop-daemon --start --oknodo --quiet \
147             --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
148         if [ $? != 0 ]; then
149             log_end_msg $?
150             exit $?
151         fi
152
153         if [ "$NEED_LOCKD" = yes ]
154         then
155             log_progress_msg "lockd"
156             start-stop-daemon --start --oknodo --quiet \
157                 --exec $PREFIX/sbin/rpc.lockd
158             if [ $? != 0 ]; then
159                 log_end_msg $?
160                 exit $?
161             fi
162         fi
163         if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
164         then
165             do_modprobe nfs
166             do_modprobe nfs4
167             if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
168             then
169                 if [ "$NEED_IDMAPD" = yes ]
170                 then
171                     log_progress_msg "idmapd"
172                     start-stop-daemon --start --oknodo --quiet \
173                             --make-pidfile --pidfile $IDMAPD_PIDFILE \
174                             --exec /usr/sbin/rpc.idmapd
175                     if [ $? != 0 ]; then
176                         log_end_msg $?
177                         exit $?
178                     fi
179                 fi
180                 if [ "$NEED_GSSD" = yes ]
181                 then
182                     do_modprobe rpcsec_gss_krb5
183                     log_progress_msg "gssd"
184                     start-stop-daemon --start --oknodo --quiet \
185                             --make-pidfile --pidfile $GSSD_PIDFILE \
186                             --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
187                     if [ $? != 0 ]; then
188                         log_end_msg $?
189                         exit $?
190                     fi
191                 fi
192             fi
193         fi
194         log_end_msg 0
195         ;;
196
197   stop)
198         log_daemon_msg "Stopping $DESC"
199
200         if [ "$NEED_GSSD" = yes ]
201         then
202             log_progress_msg "gssd"
203             start-stop-daemon --stop --oknodo --quiet \
204                     --name rpc.gssd
205             if [ $? != 0 ]; then
206                 log_end_msg $?
207                 exit $?
208             fi
209             rm -f $GSSD_PIDFILE
210         fi
211         if [ "$NEED_IDMAPD" = yes ]
212         then
213             log_progress_msg "idmapd"
214             start-stop-daemon --stop --oknodo --quiet \
215                 --name rpc.idmapd
216             if [ $? != 0 ]; then
217                 log_end_msg $?
218                 exit $?
219             fi
220             rm -f $IDMAPD_PIDFILE
221         fi
222         if [ "$NEED_LOCKD" = yes ]
223         then
224             log_progress_msg "lockd"
225             start-stop-daemon --stop --oknodo --quiet \
226                 --name rpc.lockd
227             if [ $? != 0 ]; then
228                 log_end_msg $?
229                 exit $?
230             fi
231         else
232             pkill -KILL -u root -x lockd || true
233         fi
234         log_progress_msg "statd"
235         start-stop-daemon --stop --oknodo --quiet \
236             --name rpc.statd
237         if [ $? != 0 ]; then
238             log_end_msg $?
239             exit $?
240         fi
241         do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
242         log_end_msg 0
243         ;;
244
245   status)
246         if ! pidof rpc.statd >/dev/null
247         then
248             echo "rpc.statd not running"
249             exit 3
250         fi
251
252         if [ "$NEED_GSSD" = yes ]
253         then
254             if [ ! -f "$GSSD_PIDFILE" ] || ! pidof rpc.gssd >/dev/null
255             then
256                 echo "rpc.statd running, but rpc.gssd halted"
257                 exit 3
258             fi
259         fi
260
261         if [ "$NEED_LOCKD" = yes ]
262         then
263             if ! pidof rpc.lockd >/dev/null
264             then
265                 echo "rpc.statd running, but rpc.lockd halted"
266                 exit 3
267             fi
268         fi
269             
270         if [ "$NEED_IDMAPD" = yes ]
271         then
272             if [ ! -f "$IDMAPD_PIDFILE" ] || ! pidof rpc.idmapd >/dev/null
273             then
274                 echo "rpc.statd running, but rpc.idmapd halted"
275                 exit 3
276             fi
277         fi
278
279         echo "rpc.statd running"
280         exit 0
281         ;;
282
283   restart | force-reload)
284         $0 stop
285         sleep 1
286         $0 start
287         ;;
288
289   *)
290         log_success_msg "Usage: nfs-common {start|stop|status|restart}"
291         exit 1
292         ;;
293 esac
294
295 exit 0