fshalt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. sleep 30
  35. for (i in $k){
  36. echo -n $i...
  37. switch($i){
  38. case /srv/kfs.cmd
  39. disk/kfscmd sync
  40. case *
  41. disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
  42. }
  43. sleep 2
  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/echo /tmp
  50. cp /bin/disk/kfscmd /tmp
  51. cp /bin/rc /tmp
  52. cp /bin/sed /tmp
  53. cp /bin/ns /tmp
  54. cp /bin/iostats /tmp
  55. mkdir /tmp/lib
  56. cp /rc/lib/rcmain /tmp/lib
  57. bind /tmp /rc
  58. bind /tmp /bin
  59. # put this in a shell function so this rc script doesn't get read
  60. # when it's no longer accessible
  61. fn x {
  62. echo
  63. echo -n halting...
  64. for(i in $f) @ {
  65. echo -n $i...
  66. {
  67. echo fsys all halt
  68. if(! expect -t 60 ': ')
  69. echo -n 'not halted...' > /dev/cons
  70. } < $i >> $i
  71. }
  72. for (i in $k){
  73. echo -n $i...
  74. switch($i){
  75. case /srv/kfs.cmd
  76. kfscmd halt
  77. case *
  78. kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
  79. }
  80. }
  81. echo
  82. echo done halting
  83. if (~ $reboot yes) {
  84. echo rebooting...
  85. echo reboot >'#c/reboot'
  86. }
  87. }
  88. x