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