]> git.decadent.org.uk Git - nfs-utils.git/blob - debian/nfs-common.init
Imported Debian patch 1.0.8-6
[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=
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 # 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 #
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.
57 #
58 AUTO_NEED_IDMAPD=no
59 AUTO_NEED_GSSD=no
60
61 exec 9<&0 </etc/fstab
62
63 while read DEV MTPT FSTYPE OPTS REST
64 do
65     if [ "$FSTYPE" = "nfs4" ]; then
66         AUTO_NEED_IDMAPD=yes
67     fi
68     case "$OPTS" in
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,*)
70             AUTO_NEED_GSSD=yes
71         ;;
72     esac
73 done
74
75 exec 0<&9 9<&-
76
77 case "$NEED_IDMAPD" in
78     yes|no)     
79         ;;
80     *)
81         NEED_IDMAPD=$AUTO_NEED_IDMAPD
82         ;;
83 esac
84
85 case "$NEED_GSSD" in
86     yes|no)     
87         ;;
88     *)
89         NEED_GSSD=$AUTO_NEED_GSSD
90         ;;
91 esac
92
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
98
99 do_modprobe() {
100     modprobe -q "$1" || true
101 }
102
103 do_mount() {
104     if ! grep -E -qs "$1\$" /proc/filesystems
105     then
106         return 1
107     fi
108     if ! mountpoint -q "$2"
109     then
110         mount -t "$1" "$1" "$2"
111         return
112     fi
113     return 0
114 }
115
116 do_umount() {
117     if mountpoint -q "$1"
118     then
119         umount "$1"
120     fi
121     return 0
122 }
123
124 # See how we were called.
125 case "$1" in
126   start)
127         cd /    # daemons should have root dir as cwd
128         printf "Starting $DESC:"
129         printf " statd"
130         start-stop-daemon --start --oknodo --quiet \
131             --exec $PREFIX/sbin/rpc.statd -- $STATDOPTS
132         if [ "$NEED_LOCKD" = yes ]
133         then
134             printf " lockd"
135             start-stop-daemon --start --oknodo --quiet \
136                 --exec $PREFIX/sbin/rpc.lockd  || true
137         fi
138         if [ "$NEED_IDMAPD" = yes ] || [ "$NEED_GSSD" = yes ]
139         then
140             do_modprobe nfs
141             do_modprobe nfs4
142             if do_mount rpc_pipefs $PIPEFS_MOUNTPOINT
143             then
144                 if [ "$NEED_IDMAPD" = yes ]
145                 then
146                     printf " idmapd"
147                     start-stop-daemon --start --oknodo --quiet \
148                             --make-pidfile --pidfile $IDMAPD_PIDFILE \
149                             --exec /usr/sbin/rpc.idmapd
150                 fi
151                 if [ "$NEED_GSSD" = yes ]
152                 then
153                     do_modprobe rpcsec_gss_krb5
154                     printf " gssd"
155                     start-stop-daemon --start --oknodo --quiet \
156                             --make-pidfile --pidfile $GSSD_PIDFILE \
157                             --exec /usr/sbin/rpc.gssd -- $RPCGSSDOPTS
158                 fi
159             fi
160         fi
161         echo "."
162         ;;
163
164   stop)
165         printf "Stopping $DESC:"
166         if [ "$NEED_GSSD" = yes ]
167         then
168             printf " gssd"
169             start-stop-daemon --stop --oknodo --quiet \
170                     --name rpc.gssd
171             rm -f $GSSD_PIDFILE
172         fi
173         if [ "$NEED_IDMAPD" = yes ]
174         then
175             printf " idmapd"
176             start-stop-daemon --stop --oknodo --quiet \
177                 --name rpc.idmapd
178             rm -f $IDMAPD_PIDFILE
179         fi
180         if [ "$NEED_LOCKD" = yes ]
181         then
182             printf " lockd"
183             start-stop-daemon --stop --oknodo --quiet \
184                 --name rpc.lockd || true
185         else
186             pkill -KILL -u root -x lockd || true
187         fi
188         printf " statd"
189         start-stop-daemon --stop --oknodo --quiet \
190             --name rpc.statd
191         do_umount $PIPEFS_MOUNTPOINT 2>/dev/null || true
192         echo "."
193         ;;
194
195   status)
196         if ! pidof rpc.statd >/dev/null
197         then
198             echo "rpc.statd not running"
199             exit 3
200         fi
201
202         if [ "$NEED_GSSD" = yes ]
203         then
204             if [ ! -f "$GSSD_PIDFILE" ] || [ "$( pidof rpc.gssd )" != "$( cat $GSSD_PIDFILE )"]
205             then
206                 echo "rpc.statd running, but rpc.gssd halted"
207                 exit 3
208             fi
209         fi
210
211         if [ "$NEED_LOCKD" = yes ]
212         then
213             if ! pidof rpc.lockd >/dev/null
214             then
215                 echo "rpc.statd running, but rpc.lockd halted"
216                 exit 3
217             fi
218         fi
219             
220         if [ "$NEED_IDMAPD" = yes ]
221         then
222             if [ ! -f "$IDMAPD_PIDFILE" ] || [ "$( pidof rpc.idmapd )" != "$( cat $IDMAPD_PIDFILE )"]
223             then
224                 echo "rpc.statd running, but rpc.idmapd halted"
225                 exit 3
226             fi
227         fi
228
229         echo "rpc.statd running"
230         exit 0
231         ;;
232
233   restart | force-reload)
234         $0 stop
235         sleep 1
236         $0 start
237         ;;
238
239   *)
240         echo "Usage: nfs-common {start|stop|restart}"
241         exit 1
242         ;;
243 esac
244
245 exit 0