2011-03-30 14:14:36 +00:00
|
|
|
#!/bin/rc
|
|
|
|
# fshalt [-r] - sync (flush) and, if possible, halt all file servers
|
|
|
|
# and optionally reboot
|
|
|
|
rfork e
|
|
|
|
reboot=no
|
2011-07-21 08:45:41 +00:00
|
|
|
scram=no
|
2011-03-30 14:14:36 +00:00
|
|
|
switch ($#*) {
|
|
|
|
case 0
|
|
|
|
case 1
|
|
|
|
reboot=yes
|
|
|
|
case *
|
|
|
|
echo usage: $0 '[-r]' >[1=2]
|
|
|
|
exit usage
|
|
|
|
}
|
|
|
|
|
|
|
|
path=(/bin)
|
|
|
|
builtin cd /
|
2011-07-21 08:45:41 +00:00
|
|
|
bind -c '#s' /srv
|
|
|
|
bind '#p' /proc
|
2011-03-30 14:14:36 +00:00
|
|
|
|
|
|
|
unmount /mnt/consoles >[2]/dev/null
|
|
|
|
kill consolefs | rc # don't compete with /mnt/consoles
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
|
2011-04-20 03:49:58 +00:00
|
|
|
c=`{ls /srv/cwfs*cmd >[2]/dev/null}
|
2011-03-30 14:14:36 +00:00
|
|
|
|
|
|
|
for (i in $k){
|
|
|
|
echo -n $i...
|
|
|
|
switch($i){
|
|
|
|
case /srv/kfs.cmd
|
|
|
|
disk/kfscmd sync
|
|
|
|
case *
|
|
|
|
disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
|
|
|
|
}
|
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
2011-07-21 08:45:41 +00:00
|
|
|
# for scram, don't scram other systems
|
2011-07-20 08:26:56 +00:00
|
|
|
bind -b '#P' /dev
|
2011-07-21 08:45:41 +00:00
|
|
|
if (test -e '#P'/apm)
|
|
|
|
if (! ~ $reboot yes)
|
|
|
|
scram=yes
|
2011-07-20 08:26:56 +00:00
|
|
|
|
2011-03-30 14:14:36 +00:00
|
|
|
# halting (binaries we run can't be on the fs we're halting)
|
|
|
|
ramfs
|
|
|
|
builtin cd /tmp
|
|
|
|
cp /bin/dial/expect /tmp
|
|
|
|
cp /bin/disk/kfscmd /tmp
|
2011-04-21 03:10:08 +00:00
|
|
|
cp /bin/echo /tmp
|
2011-03-30 14:14:36 +00:00
|
|
|
cp /bin/iostats /tmp
|
|
|
|
mkdir /tmp/lib
|
|
|
|
cp /rc/lib/rcmain /tmp/lib
|
2011-04-21 03:10:08 +00:00
|
|
|
cp /bin/ns /tmp
|
|
|
|
cp /bin/rc /tmp
|
|
|
|
cp /bin/sed /tmp
|
|
|
|
cp /bin/sleep /tmp
|
2011-05-18 04:17:27 +00:00
|
|
|
cp /bin/scram /tmp
|
2011-03-30 14:14:36 +00:00
|
|
|
bind /tmp /rc
|
|
|
|
bind /tmp /bin
|
|
|
|
|
|
|
|
# put this in a shell function so this rc script doesn't get read
|
|
|
|
# when it's no longer accessible
|
|
|
|
fn x {
|
|
|
|
echo
|
|
|
|
echo -n halting...
|
|
|
|
for (i in $k){
|
|
|
|
echo -n $i...
|
|
|
|
switch($i){
|
|
|
|
case /srv/kfs.cmd
|
|
|
|
kfscmd halt
|
|
|
|
case *
|
|
|
|
kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
|
|
|
|
}
|
|
|
|
}
|
2011-04-21 03:10:08 +00:00
|
|
|
for (i in $c){
|
|
|
|
echo -n $i...
|
|
|
|
echo halt >>$i
|
|
|
|
sleep 2
|
|
|
|
}
|
2011-03-30 14:14:36 +00:00
|
|
|
echo
|
|
|
|
echo done halting
|
|
|
|
|
|
|
|
if (~ $reboot yes) {
|
|
|
|
echo rebooting...
|
|
|
|
echo reboot >'#c/reboot'
|
|
|
|
}
|
2011-07-21 08:45:41 +00:00
|
|
|
if (~ $scram yes)
|
|
|
|
scram
|
2011-03-30 14:14:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x
|