]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fshalt
c6bf8c8544a070423536569ff2bc068b9431904f
[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
28 for (i in $k){
29         echo -n $i... 
30         switch($i){
31         case /srv/kfs.cmd
32                 disk/kfscmd sync
33         case *
34                 disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
35         }
36         sleep 2
37 }
38
39 # for scram, don't scram other systems
40 bind -b '#P' /dev
41 if (test -e '#P'/apm)
42         if (! ~ $reboot yes)
43                 scram=yes
44
45 # halting (binaries we run can't be on the fs we're halting)
46 ramfs
47 builtin cd /tmp
48 cp /bin/dial/expect /tmp
49 cp /bin/disk/kfscmd /tmp
50 cp /bin/echo /tmp
51 cp /bin/iostats /tmp
52 mkdir /tmp/lib
53 cp /rc/lib/rcmain /tmp/lib
54 cp /bin/ns /tmp
55 cp /bin/rc /tmp
56 cp /bin/sed /tmp
57 cp /bin/sleep /tmp
58 cp /bin/scram /tmp
59 bind /tmp /rc
60 bind /tmp /bin
61
62 # put this in a shell function so this rc script doesn't get read
63 # when it's no longer accessible
64 fn x {
65         echo
66         echo -n halting...
67         for (i in $k){
68                 echo -n $i... 
69                 switch($i){
70                 case /srv/kfs.cmd
71                         kfscmd halt
72                 case *
73                         kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
74                 }
75         }
76         for (i in $c){
77                 echo -n $i...
78                 echo halt >>$i
79                 sleep 2
80         }
81         echo
82         echo done halting
83
84         if (~ $reboot yes) {
85                 echo rebooting...
86                 echo reboot >'#c/reboot'
87         }
88         if (~ $scram yes)
89                 scram
90 }
91
92 x