]> git.decadent.org.uk Git - nfs-utils.git/blob - debian/nfs-common.init
Imported Debian patch 1.1.0-3
[nfs-utils.git] / debian / nfs-common.init
1 #!/bin/sh
2
3 ### BEGIN INIT INFO
4 # Provides:          nfs-common
5 # Required-Start:    $time
6 # Required-Stop:     $time
7 # Default-Start:     2 3 4 5
8 # Default-Stop:      0 1 6
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.
13 ### END INIT INFO
14
15 # What is this?
16 DESC="NFS common utilities"
17
18 # Read config
19 DEFAULTFILE=/etc/default/nfs-common
20 PREFIX=
21 NEED_IDMAPD=
22 NEED_GSSD=
23 PIPEFS_MOUNTPOINT=/var/lib/nfs/rpc_pipefs
24 RPCGSSDOPTS=
25 if [ -f $DEFAULTFILE ]; then
26     . $DEFAULTFILE
27 fi
28
29 . /lib/lsb/init-functions
30
31 #
32 # Parse the fstab file, and determine whether we need idmapd and gssd. (The
33 # /etc/defaults settings, if any, will override our autodetection.) This code
34 # is partially adapted from the mountnfs.sh script in the sysvinit package.
35 #
36 AUTO_NEED_IDMAPD=no
37 AUTO_NEED_GSSD=no
38
39 if [ -f /etc/fstab ]; then
40     exec 9<&0 </etc/fstab
41
42     while read DEV MTPT FSTYPE OPTS REST
43     do
44         if [ "$FSTYPE" = "nfs4" ]; then
45             AUTO_NEED_IDMAPD=yes
46         fi
47         case "$OPTS" in
48             sec=krb5|*,sec=krb5|sec=krb5,*|*,sec=krb5i,*|sec=krb5i|*,sec=krb5i|sec=krb5i,*|*,sec=krb5i,*|sec=krb5p|*,sec=krb5p|sec=krb5p,*|*,sec=krb5p,*)
49             AUTO_NEED_GSSD=yes
50             ;;
51         esac
52     done
53
54     exec 0<&9 9<&-
55 fi
56
57 #
58 # We also need idmapd if we run an NFSv4 server. It's fairly difficult
59 # to autodetect whether there are NFSv4 exports or not, and idmapd is not a
60 # particularily heavy daemon, so we auto-enable it if we find an /etc/exports
61 # file. This does not mean that there are NFSv4 or other mounts active (or
62 # even that nfs-kernel-server is installed), but it matches what the "start"
63 # condition in nfs-kernel-server's init script does, which has a value in
64 # itself.
65 #
66 if [ -f /etc/exports ]; then
67     AUTO_NEED_IDMAPD=yes
68 fi
69
70
71 case "$NEED_IDMAPD" in
72     yes|no)     
73         ;;
74     *)
75         NEED_IDMAPD=$AUTO_NEED_IDMAPD
76         ;;
77 esac
78
79 case "$NEED_GSSD" in
80     yes|no)     
81         ;;
82     *)
83         NEED_GSSD=$AUTO_NEED_GSSD
84         ;;
85 esac
86
87 # Exit if required binaries are missing.
88 [ -x $PREFIX/sbin/rpc.statd ] || exit 0
89 [ -x /usr/sbin/rpc.idmapd   ] || [ "$NEED_IDMAPD" = no ] || exit 0
90 [ -x /usr/sbin/rpc.gssd     ] || [ "$NEED_GSSD"   = no ] || exit 0
91
92 do_modprobe() {
93     if [ -x /sbin/modprobe -a -f /proc/modules ]
94     then
95         modprobe -q "$1" || true
96     fi
97 }
98
99 do_mount() {
100     if ! grep -E -qs "$1\$" /proc/filesystems
101     then
102         return 1
103     fi
104     if ! mountpoint -q "$2"
105     then
106         mount -t "$1" "$1" "$2"
107         return
108     fi
109     return 0
110 }
111
112 do_umount() {
113     if mountpoint -q "$1"
114     then
115         umount "$1"
116     fi
117     return 0
118 }
119
120 # See how we were called.
121 case "$1" in
122   start)
123         log_daemon_msg "Starting $DESC"
124
125         log_progress_msg "statd"
126         start-stop-daemon --start --oknodo --quiet \
127             --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
128         if [ $? != 0 ]; then
129             log_end_msg $?
130             exit $?
131         fi
132
133         if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
134         then
135             do_modprobe nfs
136             do_modprobe nfs4
137             if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
138             then
139                 if [ "$NEED_IDMAPD" = yes ]
140                 then
141                     log_progress_msg "idmapd"
142                     start-stop-daemon --start --oknodo --quiet \
143                             --exec /usr/sbin/rpc.idmapd
144                     if [ $? != 0 ]; then
145                         log_end_msg $?
146                         exit $?
147                     fi
148                 fi
149                 if [ "$NEED_GSSD" = yes ]
150                 then
151                     do_modprobe rpcsec_gss_krb5
152                     log_progress_msg "gssd"
153
154                     # we need this available; better to fail now than
155                     # mysteriously on the first mount
156                     if ! grep -q -E '^nfs[       ]' /etc/services; then
157                         log_action_end_msg 1 "broken /etc/services, please see /usr/share/doc/nfs-common/README.Debian.nfsv4"
158                         exit 1
159                     fi
160
161                     start-stop-daemon --start --oknodo --quiet \
162                             --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
163                     if [ $? != 0 ]; then
164                         log_end_msg $?
165                         exit $?
166                     fi
167                 fi
168             fi
169         fi
170         log_end_msg 0
171         ;;
172
173   stop)
174         log_daemon_msg "Stopping $DESC"
175
176         if [ "$NEED_GSSD" = yes ]
177         then
178             log_progress_msg "gssd"
179             start-stop-daemon --stop --oknodo --quiet \
180                     --name rpc.gssd
181             if [ $? != 0 ]; then
182                 log_end_msg $?
183                 exit $?
184             fi
185         fi
186         if [ "$NEED_IDMAPD" = yes ]
187         then
188             log_progress_msg "idmapd"
189             start-stop-daemon --stop --oknodo --quiet \
190                 --name rpc.idmapd
191             if [ $? != 0 ]; then
192                 log_end_msg $?
193                 exit $?
194             fi
195         fi
196         log_progress_msg "statd"
197         start-stop-daemon --stop --oknodo --quiet \
198             --name rpc.statd
199         if [ $? != 0 ]; then
200             log_end_msg $?
201             exit $?
202         fi
203         do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
204         log_end_msg 0
205         ;;
206
207   status)
208         if ! pidof rpc.statd >/dev/null
209         then
210             echo "rpc.statd not running"
211             exit 3
212         fi
213
214         if [ "$NEED_GSSD" = yes ]
215         then
216             if ! pidof rpc.gssd >/dev/null
217             then
218                 echo "rpc.statd running, but rpc.gssd halted"
219                 exit 3
220             fi
221         fi
222
223         if [ "$NEED_IDMAPD" = yes ]
224         then
225             if ! pidof rpc.idmapd >/dev/null
226             then
227                 echo "rpc.statd running, but rpc.idmapd halted"
228                 exit 3
229             fi
230         fi
231
232         echo "rpc.statd running"
233         exit 0
234         ;;
235
236   restart | force-reload)
237         $0 stop
238         sleep 1
239         $0 start
240         ;;
241
242   *)
243         log_success_msg "Usage: nfs-common {start|stop|status|restart}"
244         exit 1
245         ;;
246 esac
247
248 exit 0