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.

318 lines
7.6 KiB

28 years ago
28 years ago
28 years ago
  1. # $OpenBSD: rc,v 1.28 1996/12/22 20:14:09 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. ( ulimit -d 32768; 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. if [ X"${rfc1323}" = X"NO" ]; then
  70. echo 'disabling rfc1323'; sysctl -w net.inet.tcp.rfc1323=0
  71. fi
  72. # clean up left-over files
  73. rm -f /etc/nologin
  74. rm -f /var/spool/lock/LCK.*
  75. rm -f /var/spool/uucp/STST/*
  76. (cd /var/run && { rm -rf -- *; install -c -m 664 -g utmp /dev/null utmp; })
  77. echo -n 'starting rpc daemons:'
  78. # $portmap is imported from /etc/netstart;
  79. # if $portmap == YES, the portmapper is started.
  80. if [ X"${portmap}" = X"YES" ]; then
  81. echo -n ' portmap'; portmap
  82. fi
  83. if [ -d /var/yp/binding ]; then
  84. if [ -d /var/yp/`domainname` ]; then
  85. # yp server capabilities needed...
  86. echo -n ' ypserv'; ypserv
  87. #echo -n ' ypxfrd'; ypxfrd
  88. fi
  89. echo -n ' ypbind'; ypbind
  90. if [ -d /var/yp/`domainname` ]; then
  91. # if we are the master server, run rpc.yppasswdd
  92. _host1=`ypwhich -m passwd 2> /dev/null`
  93. _host2=`hostname`
  94. if [ `grep '^lookup' /etc/resolv.conf | grep yp | wc -c` -ne 0 ]; then
  95. _host1=`ypmatch $_host1 hosts | cut -d' ' -f2`
  96. _host2=`ypmatch $_host2 hosts | cut -d' ' -f2 | head -1`
  97. else
  98. _host1=`nslookup $_host1 | grep '^Name: ' | \
  99. sed -e 's/^Name: //'`
  100. _host2=`nslookup $_host2 | grep '^Name: ' | \
  101. sed -e 's/^Name: //'`
  102. fi
  103. if [ "$_host2" = "$_host1" ]; then
  104. echo -n ' rpc.yppasswdd'; rpc.yppasswdd
  105. fi
  106. fi
  107. fi
  108. # $nfs_server is imported from /etc/netstart;
  109. # if $nfs_server == YES, the machine is setup for being an nfs server
  110. if [ X${nfs_server} = X"YES" -a -r /etc/exports ]; then
  111. rm -f /var/db/mountdtab
  112. echo -n > /var/db/mountdtab
  113. echo -n ' mountd'; mountd
  114. echo -n ' nfsd'; nfsd -tun 4
  115. fi
  116. # $nfs_client is imported from /etc/netstart;
  117. # if $nfs_client == YES, the machine is setup for being an nfs client
  118. if [ X${nfs_client} = X"YES" ]; then
  119. echo -n ' nfsiod'; nfsiod -n 4
  120. fi
  121. if [ X${amd} = X"YES" -a -d ${amd_dir} -a -r ${amd_master} ]; then
  122. echo -n ' amd'
  123. amd -l syslog -x error,noinfo,nostats -p \
  124. -a ${amd_dir} `cat ${amd_master}` > /var/run/amd.pid
  125. fi
  126. echo '.'
  127. mount -a -t nfs
  128. echo -n 'starting system logger'
  129. rm -f /dev/log
  130. syslogd
  131. # $timed_flags is imported from /etc/netstart;
  132. # if $timed_flags == NO, timed isn't run.
  133. if [ "X${timed_flags}" != X"NO" ]; then
  134. echo -n ', time daemon'; timed $timed_flags
  135. fi
  136. echo '.'
  137. # /var/crash should be a directory or a symbolic link
  138. # to the crash directory if core dumps are to be saved.
  139. if [ -d /var/crash ]; then
  140. echo checking for core dump...
  141. savecore /var/crash
  142. fi
  143. echo -n 'checking quotas:'
  144. quotacheck -a
  145. echo ' done.'
  146. quotaon -a
  147. # build ps databases
  148. echo 'building databases...'
  149. kvm_mkdb /bsd
  150. dev_mkdb
  151. chmod 666 /dev/tty[pqrs]*
  152. # check the password temp/lock file
  153. if [ -f /etc/ptmp ]; then
  154. logger -s -p auth.err \
  155. 'password file may be incorrect -- /etc/ptmp exists'
  156. fi
  157. virecovery=/var/tmp/vi.recover/recover.*
  158. if [ "$virecovery" != "/var/tmp/vi.recover/recover.*" ]; then
  159. echo preserving editor files
  160. for i in $virecovery; do
  161. sendmail -t < $i
  162. done
  163. fi
  164. echo clearing /tmp
  165. # prune quickly with one rm, then use find to clean up /tmp/[lq]*
  166. # (not needed with mfs /tmp, but doesn't hurt there...)
  167. (cd /tmp && rm -rf [a-km-pr-zA-Z]* &&
  168. find . ! -name . ! -name lost+found ! -name quota.user \
  169. ! -name quota.group -exec rm -rf -- {} \; -type d -prune)
  170. if [ -f /var/account/acct ]; then
  171. echo 'turning on accounting'; accton /var/account/acct
  172. fi
  173. echo -n standard daemons:
  174. echo -n ' cron'; cron
  175. echo '.'
  176. echo -n starting network daemons:
  177. # $gated and $routed_flags are imported from /etc/netstart.
  178. # If $gated == YES, gated is used; otherwise routed.
  179. # If $routed_flags == NO, routed isn't run.
  180. if [ X${gated} = X"YES" -a -r /etc/gated.conf ]; then
  181. echo -n ' gated'; gated $gated_flags
  182. elif [ "X${routed_flags}" != X"NO" ]; then
  183. echo -n ' routed'; routed $routed_flags
  184. fi
  185. # $mrouted_flags is imported from /etc/netstart;
  186. # If $mrouted_flags == NO, then mrouted isn't run.
  187. if [ "X${mrouted_flags}" != X"NO" ]; then
  188. echo -n ' mrouted'; mrouted $mrouted_flags
  189. fi
  190. # $named_flags is imported from /etc/netstart;
  191. # if $named_flags != NO, named is run.
  192. if [ "X${named_flags}" != X"NO" ]; then
  193. echo -n ' named'; named $named_flags
  194. fi
  195. # $rwhod is imported from /etc/netstart;
  196. # if $rwhod == YES, rwhod is run.
  197. if [ X${rwhod} = X"YES" ]; then
  198. echo -n ' rwhod'; rwhod
  199. fi
  200. if [ X${lpd} = X"YES" ]; then
  201. echo -n ' printer'; lpd
  202. fi
  203. # $sendmail_flags is imported from /etc/netstart;
  204. # If $sendmail_flags == NO or /etc/sendmail.cf doesn't exist, then
  205. # sendmail isn't run. We call sendmail with a full path so that
  206. # SIGHUP works.
  207. if [ "X${sendmail_flags}" != X"NO" -a -r /etc/sendmail.cf ]; then
  208. echo -n ' sendmail'; /usr/sbin/sendmail ${sendmail_flags}
  209. fi
  210. if [ X${inetd} = X"YES" ]; then
  211. echo -n ' inetd'; inetd
  212. fi
  213. # $rarpd_flags is imported from /etc/netstart;
  214. # If $rarpd_flags == NO or /etc/ethers doesn't exist, then
  215. # rarpd isn't run.
  216. if [ "X${rarpd_flags}" != X"NO" -a -r /etc/ethers ]; then
  217. echo -n ' rarpd'; rarpd ${rarpd_flags}
  218. fi
  219. # $bootparamd_flags is imported from /etc/netstart;
  220. # If $bootparamd_flags == NO or /etc/bootparams doesn't exist, then
  221. # bootparamd isn't run.
  222. if [ "X${bootparamd_flags}" != X"NO" -a -r /etc/bootparams ]; then
  223. echo -n ' rpc.bootparamd'; rpc.bootparamd ${bootparamd_flags}
  224. fi
  225. # $rbootd_flags is imported from /etc/netstart;
  226. # If $rbootd_flags == NO or /etc/rbootd.conf doesn't exist, then
  227. # rbootd isn't run.
  228. if [ "X${rbootd_flags}" != X"NO" -a -r /etc/rbootd.conf ]; then
  229. echo -n ' rbootd'; rbootd ${rbootd_flags}
  230. fi
  231. echo '.'
  232. if [ -f /sbin/kbd -a -f /etc/kbdtype ]; then
  233. kbd `cat /etc/kbdtype`
  234. fi
  235. # patch /etc/motd
  236. if [ ! -f /etc/motd ]; then
  237. install -c -o root -g wheel -m 664 /dev/null /etc/motd
  238. fi
  239. T=/tmp/_motd
  240. rm -f $T
  241. sysctl -n kern.version | sed 1q > $T
  242. echo "" >> $T
  243. sed '1,/^$/d' < /etc/motd >> $T
  244. cmp -s $T /etc/motd || cp $T /etc/motd
  245. rm -f $T
  246. if [ -f /sbin/ldconfig ]; then
  247. echo 'creating runtime link editor directory cache.'
  248. _LIBS=
  249. if [ -d /usr/local/lib ]; then
  250. _LIBS="$_LIBS /usr/local/lib"
  251. fi
  252. if [ -d /usr/X11R6/lib ]; then
  253. _LIBS="$_LIBS /usr/X11R6/lib"
  254. fi
  255. ldconfig $_LIBS
  256. fi
  257. # Kerberos runs ONLY on the Kerberos server machine
  258. if [ X${kerberos_server} = X"YES" ]; then
  259. echo 'kerberos server'; kerberos >> /var/log/kerberos.log &
  260. fi
  261. . /etc/rc.local
  262. date
  263. exit 0