plan9fox/rc/bin/fshalt

78 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/rc
# fshalt [-r] - sync (flush) and, if possible, halt all file servers
# and optionally reboot
rfork en
reboot=no
2011-07-21 08:45:41 +00:00
scram=no
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
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}
2012-08-07 16:43:13 +00:00
h=`{ls /srv/hjfs*cmd >[2]/dev/null}
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
2012-06-29 14:55:48 +00:00
if(! ~ $reboot yes){
if (test -e '#P'/apm)
2011-07-21 08:45:41 +00:00
scram=yes
2012-06-29 14:55:48 +00:00
if (test -e '#P'/acpitbls -a -e '#P'/iow)
scram=yes
}
2011-07-20 08:26:56 +00:00
# halting (binaries we run can't be on the fs we're halting)
ramfs
builtin cd /tmp
2011-04-21 03:10:08 +00:00
cp /bin/echo /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
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)
2012-08-07 16:43:13 +00:00
echo halt >>$i
for (i in $c $h){
echo -n $i...
while(test -e $i)
sleep 1
2012-08-07 16:43:13 +00:00
}
echo
echo done halting
if (~ $reboot yes) {
echo rebooting...
echo reboot >'#c/reboot'
}
2012-06-29 14:55:48 +00:00
if (~ $scram yes){
2011-07-21 08:45:41 +00:00
scram
2012-06-29 14:55:48 +00:00
echo 'It''s now safe to turn off your computer'
}
}
x