macos-tuning-20080521
[openafs.git] / src / afsd / afs.rc.darwin
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 # Portions Copyright (c) 2003 Apple Computer, Inc.
10 #
11 # Updated to match standard service scripts
12 # Phil Holland <hollandp@umich.edu> 6/11/04
13
14 . /etc/rc.common
15
16 #
17 # Variable Definition Section
18 #
19 CheckForNetwork
20
21 VICEETC=/usr/vice/etc
22 AFSD=$VICEETC/afsd
23 if [ -r /var/db/openafs ]; then
24     VICEETC=/var/db/openafs/etc
25     AFSD=/usr/sbin/afsd
26 fi
27
28 CONFIG=$VICEETC/config
29 AFSDOPT=$CONFIG/afsd.options
30 PACKAGE=$CONFIG/package.options
31
32 LARGE="-stat 2800 -dcache 2400 -daemons 5 -volumes 128"
33 MEDIUM="-stat 2000 -dcache 800 -daemons 3 -volumes 70"
34 SMALL="-stat 300 -dcache 100 -daemons 2 -volumes 50"
35
36 if [ -x /usr/sbin/kextstat ]; then KMODSTAT=/usr/sbin/kextstat; fi
37 if [ -x /usr/sbin/kmodstat ]; then KMODSTAT=/usr/sbin/kmodstat; fi
38
39 if [ -f $CONFIG/afs.conf ]; then
40     . $CONFIG/afs.conf
41 fi
42
43 # Check this file second so that if users have altered the file, it will
44 # override the default options
45 if [ -f $AFSDOPT ]; then
46     OPTIONS=`cat $AFSDOPT`
47 fi
48
49 StartService()
50 {
51     echo "Starting OpenAFS"
52
53     if [ -z "$OPTIONS" ] || [ "$OPTIONS" = "AUTOMATIC" ] ; then
54         AFSD_OPTIONS="$VERBOSE"
55     else
56         AFSD_OPTIONS="$OPTIONS $VERBOSE"
57     fi
58
59     if [ "${NETWORKUP}" = "-NO-" ]; then
60         echo $AFSD_OPTIONS | grep -e '-dynroot' || exit
61     fi
62
63 # Need the commands ps, awk, kill, sleep
64     PATH=${PATH}${PATH:+:}/sbin:/bin:/usr/bin
65
66     if [ -d $VICEETC/afs.kext ]; then
67         echo "Loading AFS kernel extensions"
68         kextload $VICEETC/afs.kext
69     else
70         echo "$VICEETC/afs.kext does not exist. Skipping AFS startup."
71         exit 1
72     fi
73
74     if $KMODSTAT | perl -e 'exit not grep /openafs/, <>' ; then
75         :
76     else
77         echo  "AFS kernel extensions failed to initialize. Skipping AFS startup."
78         exit 1
79     fi
80
81 #
82 # Start the AFS server processes if a bosserver exists
83 #
84
85     if [ -x /usr/afs/bin/bosserver ]; then
86         echo "Starting AFS Server processes"
87         /usr/afs/bin/bosserver
88         AFSD_OPTIONS="$AFSD_OPTIONS -nosettime"
89         sleep 30
90     fi
91
92 #
93 # Check that all of the client configuration files exist
94 #
95
96     for file in $AFSD $VICEETC/cacheinfo \
97         $VICEETC/ThisCell $VICEETC/CellServDB
98       do
99       if [ ! -f ${file} ]; then
100           echo "${file} does not exist. Not starting AFS client."
101           exit 1
102       fi
103     done
104
105 #
106 # Check that the root directory for AFS (/afs) 
107 # and the cache directory (/usr/vice/cache) both exist
108 #
109
110     for dir in `awk -F: '{print $1, $2}' $VICEETC/cacheinfo`
111       do
112       if [ ! -d ${dir} ]; then
113           echo "${dir} does not exist. Not starting AFS client."
114           exit 2
115       fi
116     done
117
118     echo "Starting afsd"
119     $AFSD $AFSD_OPTIONS
120
121 #
122 # From /var/db/openafs/etc/config/afs.conf, call a post-init function or
123 # command if it's been defined
124 #
125     $AFS_POST_INIT
126
127 #
128 # Call afssettings (if it exists) to set customizable parameters
129 #
130     if [ -x $CONFIG/afssettings ]; then
131         sleep 2
132         $CONFIG/afssettings
133     fi
134
135 #
136 # From /var/db/openafs/etc/config/afs.conf, set a sysname list if one was
137 # configured.
138 #
139     if [ -n "$AFS_SYSNAME" ] ; then
140         fs sysname $AFS_SYSNAME
141     fi
142
143     if [ -n "$AFS_PRECACHE" ] ; then
144         fs precache $AFS_PRECACHE
145     fi
146
147 #
148 # Run package to update the disk
149 #
150     if [ -f /usr/afsws/etc/package -a -f $PACKAGE ]; then
151         /usr/afsws/etc/package -v -o `cat $PACKAGE` > /dev/console 2>&1
152         case $? in
153             0)
154                 (echo "Package completed successfully") > /dev/console 2>&1
155                 date > /dev/console 2>&1
156             ;;
157             4)
158                 (echo "Rebooting to restart system") > /dev/console 2>&1
159                 sync
160                 /sbin/reboot
161             ;;
162             *)
163                 (echo "Package update failed; continuing") > /dev/console 2>&1
164             ;;
165         esac
166      fi
167
168 #
169 # Start AFS inetd services
170 # (See the AFS Command Ref. for notes on the proper configuration of inetd.afs)
171 #
172      if [ -f /usr/sbin/inetd.afs -a -f /etc/inetd.conf.afs ]; then
173          /usr/sbin/inetd.afs /etc/inetd.conf.afs
174      fi
175 }
176
177 StopService()
178 {
179     echo "Stopping AFS"
180
181 #
182 # If a pre-shutdown function was defined in /var/db/openafs/etc/config/afs.conf
183 # was defined, then run it
184 #
185     $AFS_PRE_SHUTDOWN
186
187     if $KMODSTAT | perl -e 'exit not grep /openafs/, <>' ; then
188         echo "Unmounting /afs"
189         umount -f /afs 2>&1 > /dev/console
190
191         echo "Shutting down afsd processes"
192         $AFSD -shutdown 2>&1 > /dev/console
193
194         echo "Unloading AFS kernel extensions"
195         kextunload $VICEETC/afs.kext 2>&1 > /dev/console
196     fi
197 }
198
199 RestartService()
200 {
201     StopService
202     StartService
203 }
204
205 RunService "${1:-start}"