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