Import Debian changes 1.8.5-1
[hcoop/debian/openafs.git] / debian / openafs-client.init
1 #! /bin/sh
2 ### BEGIN INIT INFO
3 # Provides: openafs-client
4 # Required-Start: $remote_fs $network $time
5 # Required-Stop: $remote_fs $network
6 # Should-Start: $syslog $named openafs-fileserver
7 # Should-Stop: openafs-fileserver
8 # X-Stop-After: autofs
9 # Default-Start: 2 3 4 5
10 # Default-Stop: 0 1 6
11 # Short-Description: OpenAFS client
12 # Description: Starts or stops the OpenAFS client, loading the
13 # OpenAFS kernel module as necessary.
14 ### END INIT INFO
15 #
16 # Modified by Sam Hartman <hartmans@mit.edu> for Debian
17 # Copyright 2000, International Business Machines Corporation and others.
18 # All Rights Reserved.
19 #
20 # This software has been released under the terms of the IBM Public
21 # License. For details, see the LICENSE file in the top-level source
22 # directory or online at http://www.openafs.org/dl/license10.html
23
24 # This init script bears little resemblence to the regular upstream init
25 # script at this point and is therefore maintained as a Debian-specific file.
26 # The upstream init script assumes Red Hat paths and uses insmod to load the
27 # module directly rather than using modprobe.
28
29 PATH=/bin:/usr/bin:/sbin:/usr/sbin
30
31 CACHEINFO=${CACHEINFO:-/etc/openafs/cacheinfo}
32 MODULEROOT=${MODULEROOT:-/lib/modules/`uname -r`}
33 MODULEDIR=${MODULEDIR:-$MODULEROOT/fs}
34 DKMSDIR=${DKMSDIR:-$MODULEROOT/updates/dkms}
35
36 # Exit if the package is not installed.
37 [ -x /sbin/afsd ] || exit 0
38
39 # Define LSB log_* functions and get other support infrastructure.
40 . /lib/lsb/init-functions
41
42 exec 3>/dev/null
43 exec </dev/null
44
45 # Gather up options and post startup script name, if present
46 if [ -f /etc/openafs/afs.conf ]; then
47 . /etc/openafs/afs.conf
48 fi
49
50 # Return 1 if the argument is "true".
51 is_on() {
52 if [ x"$1" = x"true" ] ; then
53 return 0
54 else
55 return 1
56 fi
57 }
58
59 # Determine if kernel module loading is disabled. If it's not, don't attempt
60 # to stop or restart AFS, since we'll end up in a bad inconsistent state.
61 is_loading_disabled() {
62 disabled=`cat /proc/sys/kernel/modules_disabled 2>/dev/null`
63 if [ "$disabled" = 1 ] ; then
64 return 0
65 else
66 return 1
67 fi
68 }
69
70 # Load the AFS client module if it's not already loaded. Set $MODULEDIR and
71 # $LIBAFS to override the default location and module name. Also check before
72 # loading whether the module is listed in the module dependencies so that we
73 # can exit with a 0 status in that case.
74 load_client() {
75 if [ -z "$LIBAFS" ] ; then
76 LIBAFS=openafs.ko
77 fi
78 if [ ! -f "$MODULEDIR/$LIBAFS" -a ! -f "$DKMSDIR/$LIBAFS" ] ; then
79 echo ""
80 cat <<EOF >&2
81 AFS module $MODULEDIR/$LIBAFS does not exist.
82 Not starting AFS. Please consider building kernel modules using
83 instructions in /usr/share/doc/openafs-client/README.modules
84 EOF
85 # We must exit successfully here or openafs-client will fail on
86 # installation unless a module is installed.
87 exit 0
88 fi
89 sawdep=0
90 if grep -q openafs "$MODULEROOT/modules.dep" ; then
91 sawdep=1
92 fi
93 LOADED=`/sbin/lsmod | fgrep openafs`
94 if [ -z "$LOADED" ] ; then
95 modprobe openafs
96 status=$?
97 if [ $status = 0 ] ; then
98 echo -n " openafs"
99 fi
100
101 # We must exit successfully here if the openafs module just isn't
102 # listed in the dependency information for modprobe, which can happen
103 # if openafs-client and the module package are installed at the same
104 # time and the module hasn't been set up yet.
105 if [ $sawdep = 0 ] ; then
106 return 0
107 else
108 return $status
109 fi
110 fi
111 return 0
112 }
113
114 # Determine which afsd options to use. /etc/openafs/afs.conf contains the
115 # settings that are checked here.
116 choose_afsd_options() {
117 if [ -z "$OPTIONS" ] || [ "$OPTIONS" = "AUTOMATIC" ] ; then
118 AFSD_OPTIONS="$VERBOSE"
119 else
120 AFSD_OPTIONS="$OPTIONS $VERBOSE"
121 fi
122
123 # These variables are from /etc/openafs/afs.conf.client and are managed
124 # automatically by debconf.
125 if is_on $AFS_AFSDB ; then
126 AFSD_OPTIONS="$AFSD_OPTIONS -afsdb"
127 fi
128 if [ "$AFS_DYNROOT" = 'Yes' ] || [ "$AFS_DYNROOT" = 'true' ] ; then
129 AFSD_OPTIONS="$AFSD_OPTIONS -dynroot"
130 elif [ "$AFS_DYNROOT" = 'Sparse' ] ; then
131 AFSD_OPTIONS="$AFSD_OPTIONS -dynroot-sparse"
132 fi
133 if is_on $AFS_FAKESTAT ; then
134 AFSD_OPTIONS="$AFSD_OPTIONS -fakestat"
135 fi
136 }
137
138 # Start afsd. Be careful not to start it if another one is already running,
139 # as that has a bad tendency to hang the system. Earlier versions of the
140 # openafs-client package put afsd in /usr/sbin.
141 start_client() {
142 if pidof /sbin/afsd >/dev/null || pidof /usr/sbin/afsd >/dev/null ; then
143 echo "."
144 else
145 choose_afsd_options
146 echo " afsd."
147 start-stop-daemon --start --quiet --exec /sbin/afsd -- $AFSD_OPTIONS
148 fi
149
150 # From /etc/openafs/afs.conf.client, whether to enable fcrypt encryption.
151 if is_on $AFS_CRYPT ; then
152 fs setcrypt on
153 fi
154
155 # From /etc/openafs/afs.conf, set a sysname list if one was configured.
156 if [ -n "$AFS_SYSNAME" ] ; then
157 fs sysname $AFS_SYSNAME
158 fi
159 }
160
161 # Kill all processes that are accessing AFS. Not enabled by default, and
162 # normally called via kill_all_afs.
163 kill_afs() {
164 signal=$1
165 mount=`grep ^'AFS ' /etc/mtab | awk '{ print $2 }'`
166 if [ -n "$mount" ] ; then
167 pids=`/usr/bin/lsof -Fp $mount | sed 's/p//'`
168 if [ -n "$pids" ] ; then
169 kill -$signal $pids > /dev/null 2>&1
170 sleep 1
171 fi
172 fi
173 }
174
175 # Repeatedly call kill_afs for a series of signals to give AFS-using processes
176 # a hope of shutting down cleanly if the system is shutting down. Not enabled
177 # by default. Enable this in /etc/openafs/afs.conf.
178 #
179 # Warns and does nothing if lsof is not installed.
180 kill_all_afs() {
181 runlevel=`runlevel | sed 's/^. //'`
182 if [ "$runlevel" -eq 0 ] || [ "$runlevel" -eq 6 ] ; then
183 if [ -x /usr/bin/lsof ] ; then
184 echo -n "Killing processes with AFS files open: "
185 kill_afs HUP
186 kill_afs TERM
187 kill_afs ABRT
188 kill_afs KILL
189 echo "done."
190 else
191 echo '/usr/bin/lsof not found, not killing processes' >&2
192 fi
193 fi
194 }
195
196
197 case "$1" in
198 start)
199 if is_on $AFS_CLIENT && test -x /sbin/afsd ; then
200 echo -n "Starting AFS services:"
201 if load_client ; then
202 start_client
203 $AFS_POST_INIT
204 else
205 echo ""
206 echo "Failed to load AFS kernel module, not starting AFS" >&2
207 exit 1
208 fi
209 fi
210 ;;
211
212 force-start)
213 if test -x /sbin/afsd ; then
214 echo -n "Starting AFS services:"
215 if load_client ; then
216 start_client
217 $AFS_POST_INIT
218 else
219 echo ""
220 echo "Failed to load AFS kernel module, not starting AFS" >&2
221 exit 1
222 fi
223 fi
224 ;;
225
226 stop|force-stop)
227 if is_loading_disabled ; then
228 echo "Module loading disabled, cannot stop AFS" >&2
229 exit 1
230 fi
231 $AFS_PRE_SHUTDOWN
232 echo -n "Stopping AFS services:"
233 if grep -q '^AFS ' /etc/mtab ; then
234 umount `grep ^'AFS ' /etc/mtab | awk '{ print $2 }'`
235 echo -n " afsd"
236 fi
237 if pidof /usr/sbin/afsd >/dev/null || pidof /sbin/afsd >/dev/null ; then
238 afsd -shutdown
239 fi
240
241 # If running with the -rmtsys option, afsd doesn't kill the rmtsys helper
242 # on afsd -shutdown. Run start-stop-daemon to make sure that everything
243 # is dead.
244 start-stop-daemon --stop --quiet --name afsd
245
246 LIBAFS=`/sbin/lsmod | awk 'BEGIN { FS = " " } /openafs/ { print $1 }'`
247 if [ -n "$LIBAFS" ] ; then
248 /sbin/rmmod $LIBAFS
249 echo -n " openafs"
250 fi
251 echo "."
252 ;;
253
254 restart|force-reload)
255 "$0" stop
256 "$0" start
257 ;;
258
259 *)
260 echo Usage: \
261 'openafs-client {start|force-start|stop|restart|force-reload}' >&2
262 exit 1
263
264 esac