Standardize License information
[openafs.git] / src / afsd / afs.rc.linux
1 #! /bin/sh
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: 345 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 # Note that AFS does not use a pid file in /var/run. It is turned off by
19 # unmounting /afs.
20
21
22 # Gather up options and post startup script name, if present
23 if [ -f /etc/sysconfig/afs ]; then
24         . /etc/sysconfig/afs
25 fi
26
27 # is_on returns 1 if value of arg is "on"
28 is_on() {
29         if  test "$1" = "on" ; then return 0
30         else return 1
31         fi
32 }
33
34 # If choose_client can't correctly determine which client to use, set
35 # LIBAFS manually.
36 choose_client() {
37
38         # Use the second field of the uname -v output instead of just
39         # doing a match on the whole thing to protect against matching
40         # a timezone named SMP -- I don't know of one, but let's be
41         # paranoid.
42
43         set X `uname -v`; shift
44         case $2 in
45         SMP) MP=.mp ;;  # MP system
46         *)   MP= ;;     # SP system
47         esac
48
49         # For now, just use uname -r to get the module version. 
50         VERSION=`uname -r`
51
52         LIBAFS=libafs-$VERSION$MP.o
53 }
54
55 #
56 # Find prefix symbol to use with insmod.  We find the unregister_filesystem
57 # string from /proc/ksyms since we know it's there.  If /proc/ksyms does not
58 # exist, we print that info to the console and use the uname -v output to
59 # decide on a prefix.
60 # unregister_filesystem_Rsmp_b240cad8 is a typcial SMP version string from
61 # a kernel built from ftp.kernel.org
62 #
63
64 KSYMS_FILE=/proc/ksyms
65 SEARCH_STR="unregister_filesystem"
66 DEFAULT_SMP_PREFIX="smp_" # Redhat kernels need "smp" instead
67 PREFIX="" # none needed for UP with <= 1Gig memory
68
69 set_prefix()
70 {
71         h='[0-9a-fA-F]'
72         h8="$h$h$h$h$h$h$h$h"
73         prefix_set=0
74
75         set X `fgrep $SEARCH_STR $KSYMS_FILE 2> /dev/null`; shift
76         str=$2
77         case $str in
78         ${SEARCH_STR}_R$h8)
79                 # No prefix required
80                 ;;
81         $SEARCH_STR)
82                 # No versioning in kernel symbols
83                 ;;
84         ${SEARCH_STR}_R*$h8)
85                 suffix=${str#${SEARCH_STR}_R}
86                 PREFIX=${suffix%$h8}
87                 ;;
88         *)
89                 case $str in
90                 '')
91                         echo afsd: Cannot find \"$SEARCH_STR\" in file $KSYMS_FILE
92                         ;;
93                 *)
94                         echo afsd: Malformed kernel version symbol \"$str\"
95                         ;;
96                 esac
97
98                 echo Guessing prefix from output of uname -v
99                 set X `uname -v`; shift
100                 case $2 in
101                 SMP)
102                         PREFIX=$DEFAULT_SMP_PREFIX
103                         ;;
104                 esac
105                 ;;
106         esac
107 }
108
109
110 MODLOADDIR=/usr/vice/etc/modload
111 # load_client loads the AFS client module if it's not already loaded. 
112 load_client() {
113         # If LIBAFS is set, use it.
114         if [ -z "$LIBAFS" ] ; then
115                 # Try to determine the right client.
116                 choose_client
117         fi
118     
119         if [ ! -f $MODLOADDIR/$LIBAFS ] ; then
120                 echo AFS module $MODLOADDIR/$LIBAFS does not exist. Not starting AFS.
121                 exit 1
122         fi
123
124         # use the prefix command if required
125         set_prefix
126         /sbin/insmod ${PREFIX:+-P $PREFIX} -f -m $MODLOADDIR/$LIBAFS > $MODLOADDIR/libafs.map 2>&1
127 }
128
129 case "$1" in 
130   start)
131         # Load kernel extensions
132         if  load_client  ; then :
133         else
134                 echo Failed to load AFS client, not starting AFS services.
135                 exit 1
136         fi
137
138         echo "Starting AFS services..... "
139         # Start bosserver, it if exists
140         if  is_on $AFS_SERVER && test -x /usr/afs/bin/bosserver  ; then
141                 /usr/afs/bin/bosserver 
142         fi
143
144         # Start AFS client
145         if  is_on $AFS_CLIENT && test -x /usr/vice/etc/afsd  ; then
146                 /usr/vice/etc/afsd ${OPTIONS}
147
148                 # Start AFS version of inetd.conf if present.
149                 if  test -f /usr/afsws/etc/inetd.conf -a -x /usr/afsws/etc/inetd.afs ; then
150                         /usr/afsws/etc/inetd.afs /usr/afsws/etc/inetd.conf
151                 fi
152                 $AFS_POST_INIT
153         fi
154
155         ;;
156
157   stop)
158         # Stop AFS
159         echo "Stopping AFS services..... "
160
161         if  is_on $AFS_CLIENT  ; then
162                 killall inetd.afs
163                 umount /afs
164         fi
165
166         if  is_on $AFS_SERVER && test -x /usr/afs/bin/bos ; then
167                 echo "Stopping AFS bosserver"
168                 /usr/afs/bin/bos shutdown localhost -localauth -wait
169                 killall -HUP bosserver
170         fi
171
172         LIBAFS=`/sbin/lsmod | fgrep libafs`
173         if [ -n "$LIBAFS" ] ; then
174                 LIBAFS=`echo $LIBAFS | awk 'BEGIN { FS = " " } { print $1 }'`
175                 /sbin/rmmod $LIBAFS
176         fi
177
178         ;;
179
180   *)
181         echo Usage: 'afs <start|stop>'
182
183 esac
184