fshalt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. path=(/bin)
  15. builtin cd /
  16. unmount /mnt/consoles >[2]/dev/null
  17. kill consolefs | rc # don't compete with /mnt/consoles
  18. sleep 1
  19. f=`{ls /srv/fscons*>[2]/dev/null}
  20. k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
  21. echo -n syncing...
  22. for(i in $f){
  23. echo -n $i...
  24. {
  25. echo
  26. dial/drain
  27. echo fsys all sync
  28. if(! dial/expect -t 120 ': ')
  29. echo -n 'not synced...' > /dev/cons
  30. } < $i >> $i
  31. }
  32. echo -n venti...
  33. venti/sync >[2]/dev/null
  34. for (i in $k){
  35. echo -n $i...
  36. switch($i){
  37. case /srv/kfs.cmd
  38. disk/kfscmd sync
  39. case *
  40. disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
  41. }
  42. sleep 2
  43. }
  44. # halting (binaries we run can't be on the fs we're halting)
  45. ramfs
  46. builtin cd /tmp
  47. cp /bin/dial/expect /tmp
  48. cp /bin/echo /tmp
  49. cp /bin/disk/kfscmd /tmp
  50. cp /bin/rc /tmp
  51. cp /bin/sed /tmp
  52. cp /bin/ns /tmp
  53. cp /bin/iostats /tmp
  54. mkdir /tmp/lib
  55. cp /rc/lib/rcmain /tmp/lib
  56. bind /tmp /rc
  57. bind /tmp /bin
  58. # put this in a shell function so this rc script doesn't get read
  59. # when it's no longer accessible
  60. fn x {
  61. echo
  62. echo -n halting...
  63. for(i in $f){
  64. echo -n $i...
  65. {
  66. echo fsys all halt
  67. if(! expect -t 60 ': ')
  68. echo -n 'not halted...' > /dev/cons
  69. } < $i >> $i
  70. }
  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. echo
  81. echo done halting
  82. if (~ $reboot yes) {
  83. echo rebooting...
  84. echo reboot >'#c/reboot'
  85. }
  86. }
  87. x