]> git.lizzy.rs Git - plan9front.git/blob - rc/bin/fshalt
add glenda to upas group on install
[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 switch ($#*) {
7 case 0
8 case 1
9         reboot=yes
10 case *
11         echo usage: $0 '[-r]' >[1=2]
12         exit usage
13 }
14
15 path=(/bin)
16 builtin cd /
17
18 setrtc
19
20 unmount /mnt/consoles >[2]/dev/null
21 kill consolefs | rc                     # don't compete with /mnt/consoles
22 sleep 1
23
24 k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
25 c=`{ls /srv/cwfs*cmd >[2]/dev/null}
26
27 for (i in $k){
28         echo -n $i... 
29         switch($i){
30         case /srv/kfs.cmd
31                 disk/kfscmd sync
32         case *
33                 disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
34         }
35         sleep 2
36 }
37
38 # halting (binaries we run can't be on the fs we're halting)
39 ramfs
40 builtin cd /tmp
41 cp /bin/dial/expect /tmp
42 cp /bin/disk/kfscmd /tmp
43 cp /bin/echo /tmp
44 cp /bin/iostats /tmp
45 mkdir /tmp/lib
46 cp /rc/lib/rcmain /tmp/lib
47 cp /bin/ns /tmp
48 cp /bin/rc /tmp
49 cp /bin/sed /tmp
50 cp /bin/sleep /tmp
51 bind /tmp /rc
52 bind /tmp /bin
53
54 # put this in a shell function so this rc script doesn't get read
55 # when it's no longer accessible
56 fn x {
57         echo
58         echo -n halting...
59         for (i in $k){
60                 echo -n $i... 
61                 switch($i){
62                 case /srv/kfs.cmd
63                         kfscmd halt
64                 case *
65                         kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
66                 }
67         }
68         for (i in $c){
69                 echo -n $i...
70                 echo halt >>$i
71                 sleep 2
72         }
73         echo
74         echo done halting
75
76         if (~ $reboot yes) {
77                 echo rebooting...
78                 echo reboot >'#c/reboot'
79         }
80 }
81
82 x