fshalt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/rc
  2. # halt - sync (flush) and, if possible, halt all file servers
  3. rfork e
  4. path=(/bin)
  5. builtin cd /
  6. f=`{ls /srv/fscons*>[2]/dev/null}
  7. k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}
  8. echo -n syncing...
  9. for(i in $f){
  10. echo -n $i...
  11. {
  12. echo fsys all sync
  13. if(! dial/expect -t 120 ': ')
  14. echo -n 'not synced...' > /dev/cons
  15. } < $i >> $i
  16. }
  17. echo -n venti...
  18. venti/sync >[2]/dev/null
  19. for (i in $k){
  20. echo -n $i...
  21. switch($i){
  22. case /srv/kfs.cmd
  23. disk/kfscmd sync
  24. case *
  25. disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
  26. }
  27. sleep 2
  28. }
  29. # halting (binaries we run can't be on the fs we're halting)
  30. ramfs
  31. builtin cd /tmp
  32. cp /bin/dial/expect /tmp
  33. cp /bin/echo /tmp
  34. cp /bin/disk/kfscmd /tmp
  35. cp /bin/rc /tmp
  36. cp /bin/sed /tmp
  37. cp /bin/ns /tmp
  38. cp /bin/iostats /tmp
  39. mkdir /tmp/lib
  40. cp /rc/lib/rcmain /tmp/lib
  41. bind /tmp /rc
  42. bind /tmp /bin
  43. # put this in a shell function so this rc script doesn't get read
  44. # when it's no longer accessible
  45. fn x {
  46. echo
  47. echo -n halting...
  48. for(i in $f){
  49. echo -n $i...
  50. {
  51. echo fsys all halt
  52. if(! expect -t 60 ': ')
  53. echo -n 'not halted...' > /dev/cons
  54. } < $i >> $i
  55. }
  56. for (i in $k){
  57. echo -n $i...
  58. switch($i){
  59. case /srv/kfs.cmd
  60. kfscmd halt
  61. case *
  62. kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
  63. }
  64. }
  65. echo
  66. echo done
  67. }
  68. x