Change wiki ref to wiki.openafs.org from stanford.edu
[openafs.git] / src / afsd / afs.rc.solaris.2_5
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         awkfield2='$2'
39         pid=`ps -ef | awk "/$1/ && ! /awk/ {print $awkfield2}"`
40         [ "$pid" != "" ] && kill -KILL $pid
41 }
42
43 case $1 in
44 'start')
45
46 #
47 # Make sure afs exists in /etc/name_to_sysnum
48 #
49 if grep -s "afs" /etc/name_to_sysnum > /dev/null; then
50     echo "Entry for afs already exists in /etc/name_to_sysnum"
51 else
52     echo "Creating entry for afs in /etc/name_to_sysnum"
53     cp /etc/name_to_sysnum /etc/name_to_sysnum.orig
54     sed '/nfs/i\
55 afs                     105' /etc/name_to_sysnum > /tmp/name_to_sysnum
56     mv /tmp/name_to_sysnum /etc/name_to_sysnum
57     echo "Rebooting now for new /etc/name_to_sysnum to take effect"
58     reboot
59 fi
60
61 #
62 # Load kernel extensions
63 #
64
65 # nfssrv has to be loaded first
66 if [ -f /kernel/misc/nfssrv ]; then
67         echo "Loading NFS server kernel extensions"
68         modload /kernel/misc/nfssrv
69 else
70         echo "/kernel/misc/nfssrv does not exist. Skipping AFS startup."
71         exit 1
72 fi
73
74 if [ -f /kernel/fs/afs ]; then
75         echo "Loading AFS kernel extensions"
76         modload /kernel/fs/afs
77 else
78         echo "/kernel/fs/afs does not exist. Skipping AFS startup."
79         exit 1
80 fi
81
82 #
83 # Start the AFS server processes if a bosserver exists
84 #
85
86 if [ -x /usr/afs/bin/bosserver ]; then
87         echo "Starting AFS Server processes"
88         /usr/afs/bin/bosserver
89         OPTIONS="$OPTIONS -nosettime"
90         sleep 30
91 fi
92
93 #
94 # Check that all of the client configuration files exist
95 #
96
97 for file in /usr/vice/etc/afsd /usr/vice/etc/cacheinfo \
98             /usr/vice/etc/ThisCell /usr/vice/etc/CellServDB
99 do
100         if [ ! -f ${file} ]; then
101                 echo "${file} does not exist. Not starting AFS client."
102                 exit 1
103         fi
104 done
105
106 #
107 # Check that the root directory for AFS (/afs) 
108 # and the cache directory (/usr/vice/cache) both exist
109 #
110
111 for dir in `awk -F: '{print $1, $2}' /usr/vice/etc/cacheinfo`
112 do
113         if [ ! -d ${dir} ]; then
114                 echo "${dir} does not exist. Not starting AFS client."
115                 exit 2
116         fi
117 done
118
119 echo "Starting afsd"
120 /usr/vice/etc/afsd $OPTIONS
121
122 #
123 # Run package to update the disk
124 #
125 if [ -f /usr/afsws/etc/package -a -f $PACKAGE ]; then
126         /usr/afsws/etc/package -v -o `cat $PACKAGE` > /dev/console 2>&1
127 case $? in
128 0)
129         (echo "Package completed successfully") > /dev/console 2>&1
130         date > /dev/console 2>&1
131         ;;
132 4)
133         (echo "Rebooting to restart system") > /dev/console 2>&1
134         sync
135         /etc/reboot
136         ;;
137 *)
138         (echo "Package update failed; continuing") > /dev/console 2>&1
139         ;;
140 esac
141
142 fi
143
144 #
145 # Start AFS inetd services
146 # (See the AFS Command Ref. for notes on the proper configuration of inetd.afs)
147 #
148 if [ -f /usr/sbin/inetd.afs -a -f /etc/inetd.conf.afs ]; then
149         /usr/sbin/inetd.afs /etc/inetd.conf.afs
150 fi
151
152 echo ;;
153
154 'stop')
155
156 #
157 # Stop the AFS inetd and server processes
158 # Note that the afsd processes cannot be killed
159 #
160
161 echo "Killing inetd.afs"
162 killproc inetd.afs
163
164 bosrunning=`ps -ef | awk '/bosserver/ && ! /awk/'`
165 if [ "${bosrunning}" != "" ]; then
166         echo "Shutting down AFS server processes"
167         /usr/afs/bin/bos shutdown localhost -localauth -wait
168         echo "Killing AFS bosserver"
169         killproc bosserver
170 fi
171
172 echo ;;
173
174 *)      echo "Invalid option supplied to $0"
175         exit 1;;
176 esac