solaris-x8664-support-20050216
[openafs.git] / src / afsd / afs.rc.solaris
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.rc: rc script for AFS on Solaris 2.x platforms
10 #
11 # Install this script as /etc/init.d/afs.rc
12 # then make links like this:
13 # ln -s ../init.d/afs.rc /etc/rc0.d/K66afs
14 # ln -s ../init.d/afs.rc /etc/rc3.d/S99afs 
15 #
16 CONFIG=/usr/vice/etc/config
17 AFSDOPT=$CONFIG/afsd.options
18 PACKAGE=$CONFIG/package.options
19
20 # EXTRAOPTS can be used to enable/disable AFSDB support (-afsdb)
21 # and Dynroot (dynamically-generated /afs) support (-dynroot).
22 EXTRAOPTS="-afsdb"
23
24 LARGE="-stat 2800 -dcache 2400 -daemons 5 -volumes 128"
25 MEDIUM="-stat 2000 -dcache 800 -daemons 3 -volumes 70"
26 SMALL="-stat 300 -dcache 100 -daemons 2 -volumes 50"
27
28 if [ -f $AFSDOPT ]; then
29     OPTIONS=`cat $AFSDOPT`
30 else
31     OPTIONS="$MEDIUM $EXTRAOPTS"
32 fi
33
34 # Need the commands ps, awk, kill, sleep
35 PATH=${PATH}${PATH:+:}/sbin:/bin:/usr/bin
36
37 killproc() {            # kill the named process(es)
38         fpid='$2'
39         fproc='$9'
40         pid=`ps -ef | \
41            awk "$fproc == \"$1\" || $fproc ~ /.*\/$1/ { print $fpid }"`
42         [ "$pid" != "" ] && kill -KILL $pid
43 }
44
45 case $1 in
46 'start')
47
48 #
49 # Make sure afs exists in /etc/name_to_sysnum
50 #
51 if grep -s "afs" /etc/name_to_sysnum > /dev/null; then
52     echo "Entry for afs already exists in /etc/name_to_sysnum"
53 else
54     echo "Creating entry for afs in /etc/name_to_sysnum"
55     cp /etc/name_to_sysnum /etc/name_to_sysnum.orig
56     sed '/nfs/i\
57 afs                     105' /etc/name_to_sysnum > /tmp/name_to_sysnum
58     mv /tmp/name_to_sysnum /etc/name_to_sysnum
59     echo "Rebooting now for new /etc/name_to_sysnum to take effect"
60     reboot
61 fi
62
63 #
64 # Load kernel extensions
65 #
66
67 if [ -f /kernel/fs/afs ]; then
68         echo "Loading AFS kernel extensions"
69         modload /kernel/fs/afs
70 else
71         echo "/kernel/fs/afs does not exist. Skipping AFS startup."
72         exit 1
73 fi
74
75 #
76 # Start the AFS server processes if a bosserver exists
77 #
78
79 if [ -x /usr/afs/bin/bosserver ]; then
80         echo "Starting AFS Server processes"
81         /usr/afs/bin/bosserver
82         OPTIONS="$OPTIONS -nosettime"
83         sleep 30
84 fi
85
86 #
87 # Check that all of the client configuration files exist
88 #
89
90 for file in /usr/vice/etc/afsd /usr/vice/etc/cacheinfo \
91             /usr/vice/etc/ThisCell /usr/vice/etc/CellServDB
92 do
93         if [ ! -f ${file} ]; then
94                 echo "${file} does not exist. Not starting AFS client."
95                 exit 1
96         fi
97 done
98
99 #
100 # Check that the root directory for AFS (/afs) 
101 # and the cache directory (/usr/vice/cache) both exist
102 #
103
104 for dir in `awk -F: '{print $1, $2}' /usr/vice/etc/cacheinfo`
105 do
106         if [ ! -d ${dir} ]; then
107                 echo "${dir} does not exist. Not starting AFS client."
108                 exit 2
109         fi
110 done
111
112 echo "Starting afsd"
113 /usr/vice/etc/afsd $OPTIONS
114
115 #
116 # Run package to update the disk
117 #
118 if [ -f /usr/afsws/etc/package -a -f $PACKAGE ]; then
119         /usr/afsws/etc/package -v -o `cat $PACKAGE` > /dev/console 2>&1
120 case $? in
121 0)
122         (echo "Package completed successfully") > /dev/console 2>&1
123         date > /dev/console 2>&1
124         ;;
125 4)
126         (echo "Rebooting to restart system") > /dev/console 2>&1
127         sync
128         /etc/reboot
129         ;;
130 *)
131         (echo "Package update failed; continuing") > /dev/console 2>&1
132         ;;
133 esac
134
135 fi
136
137 #
138 # Start AFS inetd services
139 # (See the AFS Command Ref. for notes on the proper configuration of inetd.afs)
140 #
141 if [ -f /usr/sbin/inetd.afs -a -f /etc/inetd.conf.afs ]; then
142         /usr/sbin/inetd.afs /etc/inetd.conf.afs
143 fi
144
145 echo ;;
146
147 'stop')
148
149 #
150 # Stop the AFS inetd and server processes
151 # Note that the afsd processes cannot be killed
152 #
153
154 echo "Killing inetd.afs"
155 killproc inetd.afs
156
157 bosrunning=`ps -ef | awk '/bosserver/ && ! /awk/ && ! /dcebos/'`
158 if [ "${bosrunning}" != "" ]; then
159         echo "Shutting down AFS server processes"
160         /usr/afs/bin/bos shutdown localhost -localauth -wait
161         echo "Killing AFS bosserver"
162         killproc bosserver
163 fi
164
165 echo ;;
166
167 *)      echo "Invalid option supplied to $0"
168         exit 1;;
169 esac