Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
7.2 KiB

28 years ago
  1. # $OpenBSD: rc,v 1.22 1996/07/27 01:39:04 deraadt Exp $
  2. # System startup script run by init on autoboot
  3. # or after single-user.
  4. # Output and error are redirected to console by init,
  5. # and the console is the controlling terminal.
  6. stty status '^T'
  7. # Set shell to ignore SIGINT (2), but not children;
  8. # shell catches SIGQUIT (3) and returns to single user after fsck.
  9. trap : 2
  10. trap : 3 # shouldn't be needed
  11. HOME=/; export HOME
  12. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  13. export PATH
  14. # Configure ccd devices.
  15. if [ -f /etc/ccd.conf ]; then
  16. ccdconfig -C
  17. fi
  18. if [ -e /fastboot ]; then
  19. echo "Fast boot: skipping disk checks."
  20. elif [ $1x = autobootx ]; then
  21. echo "Automatic boot in progress: starting file system checks."
  22. fsck -p
  23. case $? in
  24. 0)
  25. ;;
  26. 2)
  27. exit 1
  28. ;;
  29. 4)
  30. echo "Rebooting..."
  31. reboot
  32. echo "Reboot failed; help!"
  33. exit 1
  34. ;;
  35. 8)
  36. echo "Automatic file system check failed; help!"
  37. exit 1
  38. ;;
  39. 12)
  40. echo "Boot interrupted."
  41. exit 1
  42. ;;
  43. 130)
  44. # interrupt before catcher installed
  45. exit 1
  46. ;;
  47. *)
  48. echo "Unknown error; help!"
  49. exit 1
  50. ;;
  51. esac
  52. fi
  53. trap "echo 'Boot interrupted.'; exit 1" 3
  54. swapon -a
  55. umount -a >/dev/null 2>&1
  56. mount -a -t nonfs
  57. rm -f /fastboot # XXX (root now writeable)
  58. # set flags on ttys. (do early, in case they use tty for SLIP in netstart)
  59. echo 'setting tty flags'
  60. ttyflags -a
  61. # set hostname, turn on network
  62. echo 'starting network'
  63. . /etc/netstart
  64. mount /usr >/dev/null 2>&1
  65. mount /var >/dev/null 2>&1
  66. if [ X"${ipfilter}" = X"YES" -a X"${ipmon_flags}" != X"NO" ]; then
  67. ipmon ${ipmon_flags} &
  68. fi
  69. # clean up left-over files
  70. rm -f /etc/nologin
  71. rm -f /var/spool/lock/LCK.*
  72. rm -f /var/spool/uucp/STST/*
  73. (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
  74. echo -n 'starting rpc daemons:'
  75. echo -n ' portmap'; portmap
  76. if [ -d /var/yp/binding ]; then
  77. if [ -d /var/yp/`domainname` ]; then
  78. # yp server capabilities needed...
  79. echo -n ' ypserv'; ypserv -d
  80. #echo -n ' ypxfrd'; ypxfrd
  81. fi
  82. echo -n ' ypbind'; ypbind
  83. if [ -d /var/yp/`domainname` ]; then
  84. # if we are the master server, run rpc.yppasswdd
  85. _host1=`ypwhich -m passwd 2> /dev/null`
  86. _host2=`hostname`
  87. if [ `grep '^lookup' /etc/resolv.conf | grep yp | wc -c` -ne 0 ]; then
  88. _host1=`ypmatch $_host1 hosts | cut -d' ' -f2`
  89. _host2=`ypmatch $_host2 hosts | cut -d' ' -f2 | head -1`
  90. else
  91. _host1=`nslookup $_host1 | grep '^Name: ' | \
  92. sed -e 's/^Name: //'`
  93. _host2=`nslookup $_host2 | grep '^Name: ' | \
  94. sed -e 's/^Name: //'`
  95. fi
  96. if [ "$_host2" = "$_host1" ]; then
  97. echo -n ' rpc.yppasswdd'; rpc.yppasswdd
  98. fi
  99. fi
  100. fi
  101. # $nfs_server is imported from /etc/netstart;
  102. # if $nfs_server == YES, the machine is setup for being an nfs server
  103. if [ X${nfs_server} = X"YES" -a -r /etc/exports ]; then
  104. rm -f /var/db/mountdtab
  105. echo -n > /var/db/mountdtab
  106. echo -n ' mountd'; mountd
  107. echo -n ' nfsd'; nfsd -tun 4
  108. fi
  109. # $nfs_client is imported from /etc/netstart;
  110. # if $nfs_client == YES, the machine is setup for being an nfs client
  111. if [ X${nfs_client} = X"YES" ]; then
  112. echo -n ' nfsiod'; nfsiod -n 4
  113. fi
  114. if [ X${amd} = X"YES" -a -d ${amd_dir} -a -r ${amd_master} ]; then
  115. echo -n ' amd'
  116. amd -l syslog -x error,noinfo,nostats -p \
  117. -a ${amd_dir} `cat ${amd_master}` > /var/run/amd.pid
  118. fi
  119. echo '.'
  120. mount -a -t nfs
  121. echo -n 'starting system logger'
  122. rm -f /dev/log
  123. syslogd
  124. # $timed_flags is imported from /etc/netstart;
  125. # if $timed_flags == NO, timed isn't run.
  126. if [ "X${timed_flags}" != X"NO" ]; then
  127. echo -n ', time daemon'; timed $timed_flags
  128. fi
  129. echo '.'
  130. # /var/crash should be a directory or a symbolic link
  131. # to the crash directory if core dumps are to be saved.
  132. if [ -d /var/crash ]; then
  133. echo checking for core dump...
  134. savecore /var/crash
  135. fi
  136. echo -n 'checking quotas:'
  137. quotacheck -a
  138. echo ' done.'
  139. quotaon -a
  140. # build ps databases
  141. echo 'building databases...'
  142. kvm_mkdb /bsd
  143. dev_mkdb
  144. chmod 666 /dev/tty[pqrs]*
  145. # check the password temp/lock file
  146. if [ -f /etc/ptmp ]; then
  147. logger -s -p auth.err \
  148. 'password file may be incorrect -- /etc/ptmp exists'
  149. fi
  150. virecovery=/var/tmp/vi.recover/recover.*
  151. if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
  152. echo preserving editor files
  153. for i in $virecovery; do
  154. sendmail -t < $i
  155. done
  156. fi
  157. echo clearing /tmp
  158. # prune quickly with one rm, then use find to clean up /tmp/[lq]*
  159. # (not needed with mfs /tmp, but doesn't hurt there...)
  160. (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
  161. find . ! -name . ! -name lost+found ! -name quota.user \
  162. ! -name quota.group -exec rm -rf -- {} \; -type d -prune)
  163. if [ -f /var/account/acct ]; then
  164. echo 'turning on accounting'; accton /var/account/acct
  165. fi
  166. echo -n standard daemons:
  167. echo -n ' cron'; cron
  168. echo '.'
  169. echo -n starting network daemons:
  170. # $gated and $routed_flags are imported from /etc/netstart.
  171. # If $gated == YES, gated is used; otherwise routed.
  172. # If $routed_flags == NO, routed isn't run.
  173. if [ X${gated} = X"YES" -a -r /etc/gated.conf ]; then
  174. echo -n ' gated'; gated $gated_flags
  175. elif [ "X${routed_flags}" != X"NO" ]; then
  176. echo -n ' routed'; routed $routed_flags
  177. fi
  178. # $mrouted_flags is imported from /etc/netstart;
  179. # If $mrouted_flags == NO, then mrouted isn't run.
  180. if [ "X${mrouted_flags}" != X"NO" ]; then
  181. echo -n ' mrouted'; mrouted $mrouted_flags
  182. fi
  183. # $named_flags is imported from /etc/netstart;
  184. # if $named_flags != NO, named is run.
  185. if [ "X${named_flags}" != X"NO" ]; then
  186. echo -n ' named'; named $named_flags
  187. fi
  188. # $rwhod is imported from /etc/netstart;
  189. # if $rwhod == YES, rwhod is run.
  190. if [ X${rwhod} = X"YES" ]; then
  191. echo -n ' rwhod'; rwhod
  192. fi
  193. echo -n ' printer'; lpd
  194. # $sendmail_flags is imported from /etc/netstart;
  195. # If $sendmail_flags == NO or /etc/sendmail.cf doesn't exist, then
  196. # sendmail isn't run. We call sendmail with a full path so that
  197. # SIGHUP works.
  198. if [ "X${sendmail_flags}" != X"NO" -a -r /etc/sendmail.cf ]; then
  199. echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags}
  200. fi
  201. echo -n ' inetd'; inetd
  202. # $rarpd_flags is imported from /etc/netstart;
  203. # If $rarpd_flags == NO or /etc/ethers doesn't exist, then
  204. # rarpd isn't run.
  205. if [ "X${rarpd_flags}" != X"NO" -a -r /etc/ethers ]; then
  206. echo -n ' rarpd'; rarpd ${rarpd_flags}
  207. fi
  208. # $bootparamd_flags is imported from /etc/netstart;
  209. # If $bootparamd_flags == NO or /etc/bootparams doesn't exist, then
  210. # bootparamd isn't run.
  211. if [ "X${bootparamd_flags}" != X"NO" -a -r /etc/bootparams ]; then
  212. echo -n ' rpc.bootparamd'; rpc.bootparamd ${bootparamd_flags}
  213. fi
  214. # $rbootd_flags is imported from /etc/netstart;
  215. # If $rbootd_flags == NO or /etc/rbootd.conf doesn't exist, then
  216. # rbootd isn't run.
  217. if [ "X${rbootd_flags}" != X"NO" -a -r /etc/rbootd.conf ]; then
  218. echo -n ' rbootd'; rbootd ${rbootd_flags}
  219. fi
  220. echo '.'
  221. if [ -f /sbin/kbd -a -f /etc/kbdtype ]; then
  222. kbd `cat /etc/kbdtype`
  223. fi
  224. # patch /etc/motd
  225. if [ ! -f /etc/motd ]; then
  226. install -c -o root -g wheel -m 664 /dev/null /etc/motd
  227. fi
  228. T=/tmp/_motd
  229. rm -f $T
  230. sysctl -n kern.version | sed 1q > $T
  231. echo "" >> $T
  232. sed '1,/^$/d' < /etc/motd >> $T
  233. cmp -s $T /etc/motd || cp $T /etc/motd
  234. rm -f $T
  235. if [ -f /sbin/ldconfig ]; then
  236. echo 'creating runtime link editor directory cache.'
  237. ldconfig /usr/local/lib /usr/X11R6/lib
  238. fi
  239. # Kerberos runs ONLY on the Kerberos server machine
  240. if [ X${kerberos_server} = X"YES" ]; then
  241. echo 'kerberos server'; kerberos >> /var/log/kerberos.log &
  242. fi
  243. . /etc/rc.local
  244. date
  245. exit 0