Commit | Line | Data |
---|---|---|
805e021f CE |
1 | #! /bin/bash |
2 | # Copyright 2000, International Business Machines Corporation and others. | |
3 | # All Rights Reserved. | |
4 | # | |
5 | # This software has been released under the terms of the IBM Public | |
6 | # License. For details, see the LICENSE file in the top-level source | |
7 | # directory or online at http://www.openafs.org/dl/license10.html | |
8 | ||
9 | # AFS Start and stop AFS components | |
10 | # | |
11 | # | |
12 | # chkconfig: 35 60 20 | |
13 | # description: AFS is a distributed file system which provides location | |
14 | # transparency, caching and secure authentication. | |
15 | # Additional configuration can be done in the /etc/sysconfig/afs | |
16 | # file. Read the documentation in that file for more information. | |
17 | # | |
18 | # The following section is used at least by SuSE insserv(8) | |
19 | ### BEGIN INIT INFO | |
20 | # Provides: afs | |
21 | # Required-Start: $network | |
22 | # Required-Stop: $network | |
23 | # Default-Start: 3 5 | |
24 | # Default-Stop: 0 1 2 6 | |
25 | # Description: AFS is a distributed file system which provides location | |
26 | # transparency, caching and secure authentication. | |
27 | # Additional configuration can be done in the /etc/sysconfig/afs | |
28 | # file. Read the documentation in that file for more information. | |
29 | ### END INIT INFO | |
30 | # | |
31 | # Note that AFS does not use a pid file in /var/run. It is turned off by | |
32 | # unmounting /afs. | |
33 | ||
34 | ||
35 | # check for special bootup functions | |
36 | if [ -f /etc/rc.d/init.d/functions ] ; then | |
37 | . /etc/rc.d/init.d/functions | |
38 | afs_rh=1 | |
39 | else | |
40 | # special (RedHat) functions not available... | |
41 | # so I provide neccessary replacements (e.g. for SuSE) | |
42 | ||
43 | function echo_failure () { echo -n " - failed." ; } | |
44 | ||
45 | function echo_success () { echo -n " - successful." ; } | |
46 | ||
47 | # these are hopefully all functions I use... | |
48 | fi | |
49 | ||
50 | runcmd() { | |
51 | echo -n "$1 " | |
52 | shift | |
53 | if [ "$BOOTUP" = "color" ]; then | |
54 | $* && echo_success || echo_failure | |
55 | else | |
56 | $* | |
57 | fi | |
58 | echo | |
59 | } | |
60 | ||
61 | SYSCNF=${SYSCNF:-/etc/sysconfig/afs} | |
62 | KERNEL_VERSION=`uname -r` | |
63 | ||
64 | # Gather up options and post startup script name, if present | |
65 | if [ -f $SYSCNF ] ; then | |
66 | . $SYSCNF | |
67 | fi | |
68 | ||
69 | CACHEINFO=${CACHEINFO:-/usr/vice/etc/cacheinfo} | |
70 | CACHE=${CACHEDIR:-/usr/vice/cache} | |
71 | AFS=${AFSDIR:-/afs} | |
72 | AFSD=${AFSD:-/usr/vice/etc/afsd} | |
73 | BOSSERVER=${BOSSERVER:-/usr/afs/bin/bosserver} | |
74 | BOS=${BOS:-/usr/bin/bos} | |
75 | KILLAFS=${KILLAFS:-/usr/vice/etc/killafs} | |
76 | ||
77 | # is_on returns 1 if value of arg is "on" | |
78 | is_on() { | |
79 | if test "$1" = "on" ; then return 0 | |
80 | else return 1 | |
81 | fi | |
82 | } | |
83 | ||
84 | on_network() { | |
85 | if hash ip 2>/dev/null >/dev/null; then | |
86 | IP="ip -4 addr" | |
87 | elif hash ifconfg 2>/dev/null >/dev/null; then | |
88 | IP="ifconfig -a" | |
89 | else | |
90 | echo afs: Unable to check interfaces. 1>&2 | |
91 | return 1 | |
92 | fi | |
93 | ADDRS=`LANG=C ${IP} | grep 'inet ' | grep -v 127.0.0.1 | wc -l` | |
94 | if [ "$ADDRS" = "" ]; then | |
95 | echo afs: No interfaces with IP address 1>&2 | |
96 | return 1 | |
97 | elif [ $ADDRS = 0 ]; then | |
98 | echo afs: No interfaces with IP address 1>&2 | |
99 | return 1 | |
100 | fi | |
101 | return 0 | |
102 | } | |
103 | ||
104 | # If choose_client can't correctly determine which client to use, set | |
105 | # LIBAFS manually. | |
106 | choose_client() { | |
107 | ||
108 | # Use the second field of the uname -v output instead of just | |
109 | # doing a match on the whole thing to protect against matching | |
110 | # a timezone named SMP -- I don't know of one, but let's be | |
111 | # paranoid. | |
112 | ||
113 | set X `uname -v`; shift | |
114 | case $2 in | |
115 | SMP) MP=.mp ;; # MP system | |
116 | *) MP= ;; # SP system | |
117 | esac | |
118 | ||
119 | # For now, just use uname -r to get the module version. | |
120 | case $KERNEL_VERSION in | |
121 | [1-2].[0-5].*) | |
122 | LIBAFS=libafs-$KERNEL_VERSION$MP.o | |
123 | ;; | |
124 | *) | |
125 | LIBAFS=libafs-$KERNEL_VERSION$MP.ko | |
126 | ;; | |
127 | esac | |
128 | } | |
129 | ||
130 | # | |
131 | # Find prefix symbol to use with insmod. We find the unregister_filesystem | |
132 | # string from /proc/ksyms since we know it's there. If /proc/ksyms does not | |
133 | # exist, we print that info to the console and use the uname -v output to | |
134 | # decide on a prefix. | |
135 | # unregister_filesystem_Rsmp_b240cad8 is a typcial SMP version string from | |
136 | # a kernel built from ftp.kernel.org | |
137 | # | |
138 | case $KERNEL_VERSION in | |
139 | [1-2].[0-5].*) | |
140 | KSYMS_FILE=/proc/ksyms | |
141 | ;; | |
142 | *) | |
143 | KSYMS_FILE=/proc/kallsyms | |
144 | ;; | |
145 | esac | |
146 | SEARCH_STR="unregister_filesystem" | |
147 | DEFAULT_SMP_PREFIX="smp_" # Redhat kernels need "smp" instead | |
148 | PREFIX="" # none needed for UP with <= 1Gig memory | |
149 | ||
150 | set_prefix() | |
151 | { | |
152 | h='[0-9a-fA-F]' | |
153 | h8="$h$h$h$h$h$h$h$h" | |
154 | prefix_set=0 | |
155 | ||
156 | set X `egrep "\<$SEARCH_STR" $KSYMS_FILE 2> /dev/null`; shift | |
157 | ||
158 | case $KERNEL_VERSION in | |
159 | [1-2].[0-5].*) | |
160 | str=$2 | |
161 | ;; | |
162 | *) | |
163 | str=$3 | |
164 | ;; | |
165 | esac | |
166 | case $str in | |
167 | ${SEARCH_STR}_R$h8) | |
168 | # No prefix required | |
169 | ;; | |
170 | $SEARCH_STR) | |
171 | # No versioning in kernel symbols | |
172 | ;; | |
173 | ${SEARCH_STR}_R*$h8) | |
174 | suffix=${str#${SEARCH_STR}_R} | |
175 | PREFIX=${suffix%$h8} | |
176 | ;; | |
177 | *) | |
178 | case $str in | |
179 | '') | |
180 | echo afsd: Cannot find \"$SEARCH_STR\" in file $KSYMS_FILE | |
181 | ;; | |
182 | *) | |
183 | echo afsd: Malformed kernel version symbol \"$str\" | |
184 | ;; | |
185 | esac | |
186 | ||
187 | echo Guessing prefix from output of uname -v | |
188 | set X `uname -v`; shift | |
189 | case $2 in | |
190 | SMP) | |
191 | PREFIX=$DEFAULT_SMP_PREFIX | |
192 | ;; | |
193 | esac | |
194 | ;; | |
195 | esac | |
196 | } | |
197 | ||
198 | MODLOADDIR=${MODLOADDIR:-/usr/vice/etc/modload} | |
199 | # load_client loads the AFS client module if it's not already loaded. | |
200 | load_client() { | |
201 | # If LIBAFS is set, use it. | |
202 | if [ -z "$LIBAFS" ] ; then | |
203 | # Try to determine the right client. | |
204 | choose_client | |
205 | fi | |
206 | ||
207 | if [ ! -f "$MODLOADDIR/$LIBAFS" ] ; then | |
208 | echo AFS module $MODLOADDIR/$LIBAFS does not exist. Not starting AFS. | |
209 | exit 1 | |
210 | fi | |
211 | ||
212 | # We need exportfs in order to access the cache files. Load it, but | |
213 | # ignore errors as on some machines it may be built in to the kernel, | |
214 | # not a module | |
215 | /sbin/modprobe exportfs >/dev/null 2>&1 | |
216 | ||
217 | if [ -f $KSYMS_FILE ]; then | |
218 | # use the prefix command if required | |
219 | case $KERNEL_VERSION in | |
220 | [1-2].[0-5].*) | |
221 | set_prefix | |
222 | /sbin/insmod ${PREFIX:+-P $PREFIX} -f -m $MODLOADDIR/$LIBAFS > $MODLOADDIR/libafs.map 2>&1 | |
223 | ;; | |
224 | *) | |
225 | /sbin/insmod $MODLOADDIR/$LIBAFS > $MODLOADDIR/libafs.map 2>&1 | |
226 | ;; | |
227 | esac | |
228 | else | |
229 | /sbin/insmod $MODLOADDIR/$LIBAFS > $MODLOADDIR/libafs.map 2>&1 | |
230 | fi | |
231 | } | |
232 | ||
233 | generate_cacheinfo() { | |
234 | if [ "$CACHESIZE" = "AUTOMATIC" ]; then | |
235 | LINE=`df -k $CACHE | tail -1` | |
236 | PART=`echo $LINE | awk '{ if ( ($NF != "/usr") && ($NF != "/") ) print $NF; else print "NONE";}'` | |
237 | if [ "$PART" = "NONE" ]; then | |
238 | echo "$CACHE or /usr/vice is not a separate partition" | |
239 | echo "you have to change the cachesize in $SYSCNF by hand" | |
240 | echo "AFS will be started with a VERY small cache of 8Mb." | |
241 | CACHESIZE=8000 | |
242 | else | |
243 | # Check to see if df has pretty-printed for long dev (i.e. LVM) | |
244 | FCHAR=`echo $LINE | cut -c 1` | |
245 | if [ "$FCHAR" = "/" ]; then | |
246 | PARTSIZE=`echo $LINE | awk '{print $2}'` | |
247 | else | |
248 | PARTSIZE=`echo $LINE | awk '{print $1}'` | |
249 | fi | |
250 | CACHESIZE=`echo $PARTSIZE | awk '{printf "%d",int(($1*.8)/1000)*1000}'` | |
251 | fi | |
252 | fi | |
253 | if [ "x$CACHESIZE" != "x" ]; then | |
254 | echo $AFS:$CACHE:$CACHESIZE >$CACHEINFO | |
255 | chmod 0644 $CACHEINFO | |
256 | else | |
257 | CACHESIZE=`awk -F: '{print $3}' < $CACHEINFO` | |
258 | fi | |
259 | } | |
260 | ||
261 | choose_afsdoptions() { | |
262 | if [ -z "$OPTIONS" -o "$OPTIONS" = "AUTOMATIC" ]; then | |
263 | if [ $CACHESIZE -lt 131072 ]; then | |
264 | OPTIONS=$SMALL | |
265 | elif [ $CACHESIZE -lt 524288 ]; then | |
266 | OPTIONS=$MEDIUM | |
267 | elif [ $CACHESIZE -lt 1048576 ]; then | |
268 | OPTIONS=$LARGE | |
269 | elif [ $CACHESIZE -lt 2097152 ]; then | |
270 | OPTIONS=$XLARGE | |
271 | else | |
272 | OPTIONS=$XXLARGE | |
273 | fi | |
274 | fi | |
275 | AFSD_OPTIONS="$OPTIONS $VERBOSE" | |
276 | if is_on $ENABLE_AFSDB; then | |
277 | AFSD_OPTIONS="$AFSD_OPTIONS -afsdb" | |
278 | fi | |
279 | if is_on $ENABLE_DYNROOT; then | |
280 | AFSD_OPTIONS="$AFSD_OPTIONS -dynroot" | |
281 | fi | |
282 | } | |
283 | ||
284 | case "$1" in | |
285 | start) | |
286 | if [ ! "$afs_rh" -o ! -f /var/lock/subsys/afs ]; then | |
287 | if [ `echo "$OPTIONS" | grep -c dynroot` = 0 ]; then | |
288 | on_network || exit 1 | |
289 | fi | |
290 | # Load kernel extensions | |
291 | if load_client ; then : | |
292 | else | |
293 | echo Failed to load AFS client, not starting AFS services. | |
294 | exit 1 | |
295 | fi | |
296 | ||
297 | echo "Starting AFS services..... " | |
298 | # Start bosserver, it if exists | |
299 | if is_on $AFS_SERVER && test -x $BOSSERVER ; then | |
300 | $BOSSERVER | |
301 | test "$afs_rh" && touch /var/lock/subsys/afs | |
302 | if is_on $WAIT_FOR_SALVAGE; then | |
303 | # wait for fileserver to finish salvaging | |
304 | sleep 10 | |
305 | while $BOS status localhost fs 2>&1 | grep 'Auxiliary.*salvaging'; do | |
306 | echo "Waiting for salvager to finish..... " | |
307 | sleep 10 | |
308 | done | |
309 | fi | |
310 | fi | |
311 | ||
312 | # Start AFS client | |
313 | if is_on $AFS_CLIENT && test -x $AFSD ; then | |
314 | generate_cacheinfo | |
315 | choose_afsdoptions | |
316 | $AFSD ${AFSD_OPTIONS} | |
317 | test "$afs_rh" && touch /var/lock/subsys/afs | |
318 | $AFS_POST_INIT | |
319 | fi | |
320 | fi | |
321 | ;; | |
322 | ||
323 | stop) | |
324 | if [ ! "$afs_rh" -o -f /var/lock/subsys/afs ]; then | |
325 | # Stop AFS | |
326 | echo "Stopping AFS services..... " | |
327 | ||
328 | if is_on $AFS_CLIENT ; then | |
329 | if [ -x $KILLAFS ] ; then | |
330 | runcmd "Sending all processes using /afs the TERM signal ..." $KILLAFS TERM | |
331 | runcmd "Sending all processes using /afs the KILL signal ..." $KILLAFS KILL | |
332 | fi | |
333 | umount /afs | |
334 | fi | |
335 | ||
336 | if is_on $AFS_SERVER && test -x $BOS ; then | |
337 | echo "Stopping AFS bosserver" | |
338 | $BOS shutdown localhost -localauth -wait | |
339 | killall -HUP bosserver | |
340 | fi | |
341 | ||
342 | LIBAFS=`/sbin/lsmod | fgrep libafs` | |
343 | if [ -n "$LIBAFS" ] ; then | |
344 | LIBAFS=`echo $LIBAFS | awk 'BEGIN { FS = " " } { print $1 }'` | |
345 | /sbin/rmmod $LIBAFS | |
346 | fi | |
347 | ||
348 | rm -f /var/lock/subsys/afs | |
349 | fi | |
350 | ;; | |
351 | ||
352 | restart) | |
353 | # Restart AFS | |
354 | $0 stop | |
355 | $0 start | |
356 | ;; | |
357 | ||
358 | *) | |
359 | echo Usage: 'afs <start|stop|restart>' | |
360 | ||
361 | esac | |
362 | ||
363 | exit 0 | |
364 | ||
365 | action fool the Red Hat initscripts |