summaryrefslogtreecommitdiff
path: root/rc/bin/fshalt
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 17:14:36 +0300
commit2959e1ede0ebc6fdffd7b8660f43c2ce14c9696f (patch)
treef6343b1ce11a8c87251dd27cf3d3e26b50693fa7 /rc/bin/fshalt
parente463eb40363ff4c68b1d903f4e0cdd0ac1c5977f (diff)
Import sources from 2011-03-30 iso image - rc
Diffstat (limited to 'rc/bin/fshalt')
-rwxr-xr-xrc/bin/fshalt108
1 files changed, 108 insertions, 0 deletions
diff --git a/rc/bin/fshalt b/rc/bin/fshalt
new file mode 100755
index 000000000..f288786fb
--- /dev/null
+++ b/rc/bin/fshalt
@@ -0,0 +1,108 @@
+#!/bin/rc
+# fshalt [-r] - sync (flush) and, if possible, halt all file servers
+# and optionally reboot
+rfork e
+reboot=no
+switch ($#*) {
+case 0
+case 1
+ reboot=yes
+case *
+ echo usage: $0 '[-r]' >[1=2]
+ exit usage
+}
+
+path=(/bin)
+builtin cd /
+
+setrtc
+
+# start venti flushing
+venti/sync -h localhost >[2]/dev/null &
+venti/sync >[2]/dev/null &
+
+unmount /mnt/consoles >[2]/dev/null
+kill consolefs | rc # don't compete with /mnt/consoles
+sleep 1
+
+f=`{ls /srv/fscons*>[2]/dev/null}
+k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
+
+echo -n syncing...
+for(i in $f) @ {
+ echo -n $i...
+ {
+ echo
+ dial/drain &
+ sleep 2
+ echo fsys all sync
+ if(! dial/expect -t 120 ': ')
+ echo -n 'not synced...' > /dev/cons
+ } < $i >> $i
+}
+
+# flush the last bit of possible fossil traffic
+echo -n venti...
+venti/sync -h localhost >[2]/dev/null &
+venti/sync >[2]/dev/null &
+sleep 5
+
+for (i in $k){
+ echo -n $i...
+ switch($i){
+ case /srv/kfs.cmd
+ disk/kfscmd sync
+ case *
+ disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
+ }
+ sleep 2
+}
+
+# halting (binaries we run can't be on the fs we're halting)
+ramfs
+builtin cd /tmp
+cp /bin/dial/expect /tmp
+cp /bin/echo /tmp
+cp /bin/disk/kfscmd /tmp
+cp /bin/rc /tmp
+cp /bin/sed /tmp
+cp /bin/ns /tmp
+cp /bin/iostats /tmp
+mkdir /tmp/lib
+cp /rc/lib/rcmain /tmp/lib
+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 $f) @ {
+ echo -n $i...
+ {
+ echo fsys all halt
+ if(! expect -t 60 ': ')
+ echo -n 'not halted...' > /dev/cons
+ } < $i >> $i
+ }
+
+ for (i in $k){
+ echo -n $i...
+ switch($i){
+ case /srv/kfs.cmd
+ kfscmd halt
+ case *
+ kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
+ }
+ }
+ echo
+ echo done halting
+
+ if (~ $reboot yes) {
+ echo rebooting...
+ echo reboot >'#c/reboot'
+ }
+}
+
+x