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