cpurc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/bin/rc
  2. # cpu server startup
  3. boottime=`{date}
  4. boottime=$"boottime
  5. echo cpurc starting $boottime
  6. # cs sets /dev/sysname
  7. ndb/cs -4 # bloody google's ipv6 mail sending rules
  8. sysname=`{cat /dev/sysname}
  9. # get rid of need for dirs in /n
  10. mntgen -s slashn && chmod 666 /srv/slashn
  11. # parallelism for mk
  12. NPROC = `{wc -l </dev/sysstat}
  13. # enable usb keyboard, among other usb devices
  14. if (! test -e /srv/usb && test -e '#u/usb')
  15. usb/usbd
  16. # site-specific startup
  17. listener=()
  18. if(test -e /rc/bin/cpurc.local)
  19. . /rc/bin/cpurc.local
  20. # sysname sanity checks
  21. if (~ $#sysname 0 || ~ $sysname '') {
  22. sysname = helix # default
  23. echo -n $sysname >/dev/sysname
  24. }
  25. prompt=($sysname^'# ' ' ')
  26. # cpu-specific startup
  27. # if it runs aux/listen, it must first run ndb/dns.
  28. if(! test -e '/env/*envloaded')
  29. . loadcfgpxe
  30. if(test -e /cfg/$sysname/cpurc)
  31. . /cfg/$sysname/cpurc
  32. # if we're not a server, start a dns resolver
  33. if(! test -e /srv/dns && ! test -e /env/dns) {
  34. echo -n dns...
  35. ndb/dns & # -rF
  36. }
  37. # reboot cpu server if we lose the file server
  38. if (! ~ $sysname fs)
  39. aux/reboot &
  40. # don't turn on dong's tcp port hog defense; our firewall drops
  41. # the out-of-sequence keepalives it uses, thus dropping
  42. # inside-to-outside connections after 5 minutes.
  43. #if( test -e /net/tcp/clone)
  44. # echo -n tcpporthogdefense on > /net/tcp/0/ctl
  45. # keep other bootes processes from creating capabilities (optional)
  46. rm '#¤/caphash' > /dev/null >[2=1]
  47. # start up internet if we don't already have an address
  48. if(! grep u /net/ipselftab | grep -sv 127.0.0.1) {
  49. echo -n ipconfig for ip...
  50. ip/ipconfig
  51. }
  52. if not if (~ $sysname pi) # in case on net 10 and answered by fw or airport extreme
  53. ip/ipconfig
  54. if(! grep -s 127.0.0.1 /net/ipselftab) {
  55. echo -n loopbacks...
  56. ip/ipconfig loopback /dev/null 127.1
  57. ip/ipconfig loopback /dev/null ::1 /128
  58. }
  59. # start listeners if it hasn't already been done (dicey check; auth can be slow)
  60. if(! netstat -n | grep -s '^tcp.*Listen.* (7|9|21|22|23|25|110|113|565|993|17007|17009|17010|17013) .*' &&
  61. ! ~ $listener yes) {
  62. echo -n listen...
  63. aux/listen -q &
  64. sleep 2
  65. }
  66. if(! ps|grep -s timesync) {
  67. echo -n timesync...
  68. starttimesync &
  69. sleep 2
  70. }
  71. # cpu-specific late startup
  72. if(test -e /cfg/$sysname/cpustart)
  73. . /cfg/$sysname/cpustart
  74. # prevent killing specific processes when out of memory.
  75. # processes started via listen must be killable, so exclude listen.
  76. dontkill '^(ipconfig|factotum|mntgen|venti|fossil|cs|dns|reboot)$' &
  77. # log boot and kernel information
  78. kern=`{ls -ld `{kern}}
  79. echo $"boottime $sysname $terminal $"kern >>/sys/log/boot
  80. ls -l /srv/boot | sed -e 's/.* 0 /kernel built: /' -e 's; /srv/boot;;'
  81. echo $terminal $"kern
  82. echo -n `{date} ' '; uptime
  83. echo collect kmesg...
  84. kmesg.boot &
  85. exit ''