]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fshalt
crop /lib/face/48x48x8/n/nixie.1 to the right size (was 512x512)
[plan9front.git] / rc / bin / fshalt
1 #!/bin/rc
2 # fshalt [-r] - sync (flush) and, if possible, halt all file servers
3 #       and optionally reboot
4 rfork e
5 reboot=no
6 scram=no
7 switch ($#*) {
8 case 0
9 case 1
10         reboot=yes
11 case *
12         echo usage: $0 '[-r]' >[1=2]
13         exit usage
14 }
15
16 path=(/bin)
17 builtin cd /
18 bind -c '#s' /srv
19 bind '#p' /proc
20
21 unmount /mnt/consoles >[2]/dev/null
22 kill consolefs | rc                     # don't compete with /mnt/consoles
23 sleep 1
24
25 k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
26 c=`{ls /srv/cwfs*cmd >[2]/dev/null}
27 h=`{ls /srv/hjfs*cmd >[2]/dev/null}
28
29 for (i in $k){
30         echo -n $i... 
31         switch($i){
32         case /srv/kfs.cmd
33                 disk/kfscmd sync
34         case *
35                 disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
36         }
37         sleep 2
38 }
39
40 # for scram, don't scram other systems
41 bind -b '#P' /dev
42 if(! ~ $reboot yes){
43         if (test -e '#P'/apm)
44                 scram=yes
45         if (test -e '#P'/acpitbls -a -e '#P'/iow)
46                 scram=yes
47 }
48
49 # halting (binaries we run can't be on the fs we're halting)
50 ramfs
51 builtin cd /tmp
52 cp /bin/dial/expect /tmp
53 cp /bin/disk/kfscmd /tmp
54 cp /bin/echo /tmp
55 cp /bin/iostats /tmp
56 mkdir /tmp/lib
57 cp /rc/lib/rcmain /tmp/lib
58 cp /bin/ns /tmp
59 cp /bin/rc /tmp
60 cp /bin/sed /tmp
61 cp /bin/sleep /tmp
62 cp /bin/scram /tmp
63 bind /tmp /rc
64 bind /tmp /bin
65
66 # put this in a shell function so this rc script doesn't get read
67 # when it's no longer accessible
68 fn x {
69         echo
70         echo -n halting...
71         for (i in $k){
72                 echo -n $i... 
73                 switch($i){
74                 case /srv/kfs.cmd
75                         kfscmd halt
76                 case *
77                         kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
78                 }
79         }
80         for (i in $c){
81                 echo -n $i...
82                 echo halt >>$i
83                 sleep 2
84         }
85         for(i in $h){
86                 echo -n $i
87                 echo halt >>$i
88                 sleep 2
89         }
90         echo
91         echo done halting
92
93         if (~ $reboot yes) {
94                 echo rebooting...
95                 echo reboot >'#c/reboot'
96         }
97         if (~ $scram yes){
98                 scram
99                 echo 'It''s now safe to turn off your computer'
100         }
101 }
102
103 x