plan9fox/rc/bin/fshalt
cinap_lenrek 22b28520cd fshalt: wait for fileservers command file to vanish
cwfs and hjfs create ther /srv command files with
ORCLOSE flag, so they get removed once the fileserver
terminates. we can use this to check that the fileserver
has in fact finished halting without making assumtions
about the time it should maximally take for any fileserver
to write out its buffers to disk.
2018-11-27 22:37:32 +01:00

77 lines
1.3 KiB
Bash
Executable file

#!/bin/rc
# fshalt [-r] - sync (flush) and, if possible, halt all file servers
# and optionally reboot
rfork en
reboot=no
scram=no
switch ($#*) {
case 0
case 1
reboot=yes
case *
echo usage: $0 '[-r]' >[1=2]
exit usage
}
path=(/bin)
builtin cd /
bind -c '#s' /srv
bind '#p' /proc
unmount /mnt/consoles >[2]/dev/null
kill consolefs | rc # don't compete with /mnt/consoles
sleep 1
c=`{ls /srv/cwfs*cmd >[2]/dev/null}
h=`{ls /srv/hjfs*cmd >[2]/dev/null}
# for scram, don't scram other systems
bind -b '#P' /dev
if(! ~ $reboot yes){
if (test -e '#P'/apm)
scram=yes
if (test -e '#P'/acpitbls -a -e '#P'/iow)
scram=yes
}
# halting (binaries we run can't be on the fs we're halting)
ramfs
builtin cd /tmp
cp /bin/echo /tmp
mkdir /tmp/lib
cp /rc/lib/rcmain /tmp/lib
cp /bin/ns /tmp
cp /bin/rc /tmp
cp /bin/sed /tmp
cp /bin/sleep /tmp
cp /bin/scram /tmp
cp /bin/test /tmp
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 $c $h)
echo halt >>$i
for (i in $c $h){
echo -n $i...
while(test -e $i)
sleep 1
}
echo
echo done halting
if (~ $reboot yes) {
echo rebooting...
echo reboot >'#c/reboot'
}
if (~ $scram yes){
scram
echo 'It''s now safe to turn off your computer'
}
}
x