home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / private / etc / rc < prev    next >
Text File  |  1992-05-28  |  16KB  |  500 lines

  1. #!/bin/sh -u
  2. #
  3. # This is the multi-user startup script.
  4. #
  5. # Copyright (C) 1992 by NeXT Computer, Inc.  All rights reserved.
  6. #
  7. # Note that all "echo" commands are in parentheses so that
  8. # the main shell does not open a tty and get its process group set.
  9.  
  10. HOME=/; export HOME
  11. PATH=/etc:/usr/etc:/bin:/usr/bin; export PATH
  12.  
  13. # Are we booting from a CD-ROM?  If so, switch over to /etc/rc.cdrom.
  14.  
  15. if [ -d /NextCD -a -f /etc/rc.cdrom ]; then
  16.     sh /etc/rc.cdrom $1
  17.     echo "CD-ROM boot procedure complete.  Shutting down..."
  18.     /etc/halt -e
  19.     exit 0
  20. fi
  21.  
  22. # Determine if the network is uD8Shis is used later when deciding
  23. # whether various daemons should run.  netstat -i enumerates all the 
  24. # known interfaces. Those with a '*' in their names are configured down.
  25. # Count the interfaces which are up.
  26.  
  27. NINTERFACES=`/usr/ucb/netstat -i | egrep -v '^Name|\*' | /usr/ucb/wc -l`
  28.  
  29. # The loopback interface is always enabled.  Only if we find other
  30. # interfaces do we think we are really connected to a network.
  31.  
  32. if [  $NINTERFACES -ne 1 ]; then
  33.     NETWORKUP=-YES-
  34. else
  35.     NETWORKUP=-NO-
  36. fi
  37.  
  38. # Print out an appropriate message.  MESSAGE is used later in the log.
  39.  
  40. if  [ $1x = autobootx ]; then
  41.     # (echo Automatic reboot in progress...)        >/dev/console
  42.     MESSAGE="Reboot"
  43. else
  44.     (echo Multiuser startup in progress...)            >/dev/console
  45.     MESSAGE="Multi-user startup"
  46. fi
  47.  
  48. # Check for and mount swapdisks.
  49. sh /etc/rc.swap $1
  50.  
  51. # Mount local filesystems (according to /etc/fstab).
  52. mount -vat 4.3                        >/dev/console 2>&1
  53.  
  54. # Display a message in the iconic boot window.
  55. fbshow -A -B -E -I "Checking*System*Files..."
  56.  
  57. # Attempt to recover the passwd file, if needed.  This procedure is
  58. # primarily historical and makes sense only when the passwd file is edited
  59. # using the vipw command.  
  60.  
  61. if [ -s /etc/ptmp ]; then
  62.     if [ -s /etc/passwd ]; then
  63.         (echo 'Passwd file conflict with ptmp:')    >/dev/console
  64.         ls -l /etc/passwd /etc/ptmp            >/dev/console
  65.         (echo 'Moving ptmp to ptmp.save.')        >/dev/console
  66.         mv -f /etc/ptmp /etc/ptmp.save
  67.     else
  68.         (echo 'Passwd file recovered from ptmp.')     >/dev/console
  69.         mv /etc/ptmp /etc/passwd
  70.     fi
  71. elif [ -r /etc/ptmp ]; then
  72.     (echo 'Removing passwd lock file')            >/dev/console
  73.     /bin/rm -f /etc/ptmp
  74. fi
  75.  
  76. # Start the virtual memory system.
  77. /usr/etc/mach_swapon -av                >/dev/console 2>&1
  78.  
  79. (echo -n 'Cleaning up:')                >/dev/console
  80.  
  81. # If the shutdown command was used to shut the system down, the file
  82. # /etc/nologin may have been created to prevent users from logging in.  
  83. # Remove it so that logins are enabled when the system comes up.
  84.  
  85. /bin/rm -f /etc/nologin
  86. (echo -n ' /etc/nologin')                >/dev/console
  87.  
  88. # Reset pseudo-terminals (ptys) to their default states.
  89. /usr/etc/chown root.tty /dev/tty[pqrs]*
  90. /bin/chmod 666 /dev/tty[pqrs]*
  91. (echo -n ' ptys')                    >/dev/console
  92.  
  93. # Recover files being edited by ex, vi, or e when the system was restarted.
  94. (cd /tmp; /usr/lib/ex3.7preserve -a)
  95. (echo -n ' editors')                     >/dev/console
  96.  
  97. # ClD8Tout /tmp.
  98. (cd /tmp; find . ! -name . ! -name lost+found ! -name quotas \
  99.     -exec rm -r - {} \; )
  100. (echo -n ' /tmp')                    >/dev/console
  101.  
  102. # Clear empty subdirectories of /Net.
  103. (cd /private/Net; find . ! -name . -type d -exec rmdir {} \; ) 
  104.  
  105. # Clear symlinks from /Net, too.
  106. (cd /private/Net; find . ! -name . -type l -exec rm {} \; ) 
  107. (echo -n ' /Net')                    >/dev/console
  108.  
  109. (echo '.')                        >/dev/console
  110.  
  111. # Syslog must be started before daemons are launched from rc.local.
  112. # This allows appropriate log messages to find their way to the console.
  113.  
  114. (echo -n Starting early daemons:)                >/dev/console
  115. if [ -f /usr/etc/syslogd -a -f /etc/syslog.conf ]; then
  116.     /bin/rm -f /dev/log
  117.     # If you want a timestamp to be logged periodically,
  118.     # modify the invocation of syslogd below.  For example, 
  119.     # for a half-hourly timestamp, add the argument "-m30".
  120.     /usr/etc/syslogd  && (echo -n ' syslogd')        >/dev/console
  121. fi
  122. (echo '.')                            >/dev/console
  123.  
  124. # Read the configuration information set by the HostManager application.
  125. . /etc/hostconfig
  126.  
  127. # Set up NIS domain.
  128.  
  129. if [ "${YPDOMAIN=-NO-}" != "-NO-" -a $NETWORKUP = "-YES-" ]; then
  130.     (echo "Setting NIS domainname to $YPDOMAIN")        >/dev/console
  131.     domainname $YPDOMAIN                >/dev/console 2>&1
  132. fi
  133.  
  134. # Rpc and net services are the minimal set needed to use the network.
  135. (echo -n 'Starting RPC and network services:')            >/dev/console
  136.  
  137. # Start the Mach network message server, which forwards Mach IPC over the
  138. # network and provides a name-to-port mapping service.
  139.  
  140. if [ -f /usr/etc/nmserver ]; then
  141.     /usr/etc/nmserver &                >/dev/console 2>&1
  142.     (echo -n ' nmserver')                    >/dev/console
  143. fi
  144.  
  145. # portmap converts Sun RPC program numbers into IP port numbers.
  146.  
  147. if [ -f /usr/etc/portmap ]; then
  148.     /usr/etc/portmap && (echo -n ' portmap')         >/dev/console
  149. fi
  150.  
  151. # Turn on IP routing.  If an explicit route is specified (the '*'
  152. # clause), either an IP address must be used or the router's hostname 
  153. # and IP address must be specified in the /etc/hosts file.  
  154.  
  155. case ${ROUTER=-NO-} in
  156.     -ROUTED-)
  157.     if [ -f /usr/etc/routed -a $NETWORKUP = "-YES-" ]; then
  158.         /usr/etc/routed && (echo -n ' routed')        >/dev/console
  159.     fi
  160.     ;;
  161.     -NO-)
  162.     ;;
  163.     *)
  164.     if [ -f /usr/etc/route ]; then
  165.         /usr/etc/route add default $ROUTER 1    >/dev/console 2>&1
  166.     fi
  167.     ;;
  168. esac
  169.  
  170. # Start up the netinfo daemons.  This will only complete when the
  171. # local domain has bound to its paD8U domain, if it has a parent
  172. # (that is, if the machine is on a NetInfo network).  The message:
  173. #
  174. #   Still searching for parent network administration (NetInfo) server.
  175. #   Please wait, or press 'c' to continue without network user accounts.
  176. #   See your system administrator if you need help.
  177. #
  178. # comes from the local domain's netinfod; typically, you can wait a minute
  179. # or two and the local domain will eventually find a parent. As the
  180. # message says, the system is still searching for a parent server.
  181. # Typing 'c' aborts that search, which is probably not what you want.  
  182. # (You're most likely to see this message on a network-wide NetInfo server.)
  183. #
  184. # If you would like to customize this message to include the name or
  185. # telephone number of a network administrator, edit the text of the
  186. # message in /usr/lib/NextStep/Resources/English.lproj/NetInfo.strings,
  187. # or its equivalent for your usual boot language.
  188.  
  189. if [ -f /usr/etc/nibindd ]; then
  190.     /usr/etc/nibindd && (echo -n ' netinfo')    >/dev/console 2>&1
  191. fi
  192.  
  193. # If we are in an NIS domain, start up the appropiate services.
  194.  
  195. if [ "$YPDOMAIN" != "-NO-" -a $NETWORKUP = "-YES-" ]; then
  196.     # ypserv is run on NIS servers - machines with an /etc/yp/XXX dir
  197.     if [ -f /usr/etc/ypserv -a -d /etc/yp/$YPDOMAIN ]; then
  198.         /usr/etc/ypserv && (echo -n ' ypserv')        >/dev/console
  199.     fi
  200.     if [ -f /usr/etc/ypbind ]; then
  201.         /usr/etc/ypbind && (echo -n ' ypbind')        >/dev/console
  202.     fi
  203. fi
  204.  
  205. # The lookup daemon, lookupd, provides information to client programs
  206. # through the standard C library (such as gethostbyname()).  It obtains
  207. # the information from various network services: NetInfo, DNS (also called
  208. # the Domain Name Service - named - and BIND), and NIS.
  209.  
  210. if [ -f /usr/etc/nibindd -a -f /usr/etc/lookupd ]; then
  211.     /usr/etc/lookupd && (echo -n ' lookupd')        >/dev/console
  212. fi
  213.  
  214. # Start up time service.  If you're doing any sort of network file 
  215. # access, be sure NTP is enabled and properly configured, or you may 
  216. # see very strange errors and file consistency problems.
  217. #
  218. # NeXT's ntpd has been modified to acquire the NTP server
  219. # configuration from NetInfo (the /locations/ntp directory).
  220.  
  221. case ${TIME=-AUTOMATIC-} in
  222.     -AUTOMATIC-)
  223.     if [ -f /usr/etc/ntpd -a $NETWORKUP = "-YES-" ]; then
  224.         # Synchronize our clock to the network's time.
  225.         /usr/etc/ntp -F             >/dev/null
  226.         # Fire off ntpd to keep the D8Vk in sync.
  227.         /usr/etc/ntpd && (echo -n ' ntpd')    >/dev/console
  228.     fi
  229.     ;;
  230.     -NO-)
  231.     ;;
  232.     *)
  233.     ;;
  234. esac
  235.  
  236. # biod is the NFS asynchronous block I/O daemon, which implements
  237. # NFS read-ahead and write-behind caching on NFS clients.
  238.  
  239. if [ -f /usr/etc/biod -a $NETWORKUP = "-YES-" ]; then
  240.     /usr/etc/biod 4 && (echo -n ' biod')             >/dev/console
  241. fi
  242.  
  243. (echo '.')                            >/dev/console
  244.  
  245. # Mount remote filesystems.
  246. fbshow -A -B -E -I "Mounting*File*Systems..."
  247. (echo 'Mounting remote filesystems')                >/dev/console
  248. mount -at nfs                         >/dev/console 2>&1
  249.  
  250. fbshow -A -B -E -I "Starting*System*Services..."
  251.  
  252. # Fileservice daemons are needed to import and export filesystems.
  253. (echo -n 'Starting file service daemons:')            >/dev/console
  254.  
  255. # If AppleTalk (EtherTalk) is desired, start up the AppleTalk daemon.
  256.  
  257. if [ -f /usr/etc/atalkd ]; then
  258.     if /usr/etc/atalkd >/dev/console 2>&1; then
  259.     (echo -n ' atalkd')                >/dev/console
  260.       fi
  261. fi
  262.  
  263. # Start the automounter only if /Net is a directory that is not
  264. # a symlink (symlinks to directories qualify as directories to test's
  265. # -d operation).
  266.  
  267. if [ -h /Net -o -f /Net ]; then
  268.     (echo "Warning: NeXT NFS automounter did not run.")    >/dev/console
  269. else
  270.     if [ -f /usr/etc/autonfsmount -a $NETWORKUP = "-YES-" ]; then
  271.         # The autonfsmounter will attempt a remount every 10 seconds,
  272.         # cache names for 12 hours [43200 seconds], mount things in
  273.         # /private/Net, ignore any NIS auto.master map, be triggered
  274.         # by references in the /Net directory, and use the fstab
  275.         # map (i.e., look in the mounts database -- /mounts in NetInfo,
  276.         # for example) to locate remote filesystems.
  277.         /usr/etc/autonfsmount    -tm 10 -tl 43200 \
  278.                     -a /private -m /Net -fstab \
  279.         && (echo -n ' autonfsmount') >/dev/console 2>&1
  280.     fi
  281. fi
  282.  
  283. # If exportfs finds something to export (either using /etc/exports or the
  284. # exports NetInfo directory), then start the NFS daemons (which service
  285. # NFS requests) and the mount server (which services NFS mount requests).
  286.  
  287. if [ -f /usr/etc/exportfs ]; then
  288.     # Clear the table of exported filesystems before running exportfs.
  289.     > /etc/xtab
  290.     if /usr/etc/exportfs -a >/dev/console 2>&1; then
  291.     # There is no "right" number of nfsd's. Infrequently-accessed
  292.     # servers can get by with 4 or fewer.  8 is not excessive for 
  293.     # heavily-loaded servers.
  294.     /usr/etc/nfsd 6 && (echo -n ' nfsd')         >/dev/console
  295.     /usr/etc/rpc.mD8Wd && (echo -n ' rpc.mountd')    >/dev/console 2>&1
  296.     fi
  297. fi
  298.  
  299. # If AppleShare is desired, start up the AppleShare daemon.
  300.  
  301. if [ -f /usr/etc/ashared ]; then
  302.     if /usr/etc/ashared >/dev/console 2>&1; then
  303.     (echo -n ' ashared')                >/dev/console
  304.       fi
  305. fi
  306.  
  307. # If we are a Network Master become a BOOTP and BOOTPARAM server.  This is
  308. # the only thing that depends on the value of NETMASTER from /etc/hostconfig.
  309.  
  310. if [ "${NETMASTER=-NO-}" = "-YES-" ]; then
  311.     # If /etc/bootptab file exists, become a BOOTP server.  Note
  312.     # that bootpd gets information from /etc/bootptab even when
  313.     # NetInfo is running (the per-client information comes from
  314.     # NetInfo; the global information comes from /etc/bootptab).
  315.     if [ -f /usr/etc/bootpd -a -f /etc/bootptab ]; then
  316.         /usr/etc/bootpd && (echo -n ' bootpd')        >/dev/console
  317.     fi
  318.  
  319.     # bootparamd doesn't need a flat file.  
  320.     if [ -f /usr/etc/rpc.bootparamd ]; then
  321.         /usr/etc/rpc.bootparamd && \
  322.         (echo -n ' rpc.bootparamd')            >/dev/console
  323.     fi
  324. fi
  325. (echo '.')                            >/dev/console
  326.  
  327. # Network daemons provide service to the outside world.
  328. (echo -n Starting network daemons:)                >/dev/console
  329.  
  330. # Run the Internet server daemon.
  331. if [ -f /usr/etc/inetd ]; then
  332.     /usr/etc/inetd && (echo -n ' inetd')            >/dev/console
  333. fi
  334.  
  335. # Remove junk from the outbound mail queue directory and start up
  336. # the sendmail daemon. /usr/spool/mqueue is assumed here even though
  337. # it can be changed in the sendmail configuration file.
  338. #
  339. # sendmail is started even if there's no configuration file
  340. # in /etc/sendmail/sendmail.cf.  sendmail can find a configuration file
  341. # based on information in NetInfo (the sendmail.cf property in the 
  342. # /locations/sendmail directory). If no sendmail configuration file 
  343. # exists, sendmail will exit with an appropriate error message.
  344. #
  345. # Any messages which end up in the queue, rather than being delivered
  346. # or forwarded immediately, will be processed once each hour.
  347.  
  348. if [ -f /usr/lib/sendmail ]; then
  349.     (cd /usr/spool/mqueue; rm -f nf* lf*)
  350.     /usr/lib/sendmail -bd -q1h 2>/dev/console && \
  351.         (echo -n ' sendmail')    >/dev/console
  352. fi
  353.  
  354. # lpd is the Berkeley line printer daemon.
  355.  
  356. if [ -f /usr/lib/lpd ]; then
  357.     rm -f /dev/printer
  358.     /usr/lib/lpd && (echo -n ' printer')            >/dev/console
  359. fi
  360.  
  361. # Start an SNMP agent if configured to do so.
  362.  
  363. if [ -f /usr/etc/snmpd ]; then
  364.     if /usr/etc/snmpd -N >/dev/console 2>&1; then
  365.         (echo -n D8Xmpd')                >/dev/console
  366.     fi
  367. fi
  368.  
  369. (echo '.')                            >/dev/console
  370.  
  371. # NeXT services support the application environment
  372. (echo -n 'Starting NeXT services:')                >/dev/console
  373.  
  374. # The pasteboard server is used by the AppKit.
  375.  
  376. if [ -f /usr/etc/pbs ]; then
  377.     /usr/etc/pbs &&    (echo -n ' pbs')            >/dev/console
  378. fi
  379.  
  380. # exec_faxes starts up any appropriate fax modem daemons.
  381.  
  382. if [ -f /usr/lib/NextPrinter/exec_faxes ]; then
  383.     /usr/lib/NextPrinter/exec_faxes && (echo -n ' exec_faxes')    >/dev/console
  384. fi
  385.  
  386. # If ISDN Networking is desired, start up the PhoneConnector in daemon mode.
  387.  
  388. /usr/bin/niutil -read . /localconfig/ISDN/Networking >/dev/null 2>&1
  389. if [ $? -eq 0 ]; then
  390.     if [ -f /NextAdmin/PhoneConnector.app/PhoneConnector ]; then
  391.         /NextAdmin/PhoneConnector.app/PhoneConnector -Daemon YES && \
  392.             (echo -n ' PhoneConnector')     >/dev/console
  393.     fi
  394. fi
  395.  
  396. (echo '.')                            >/dev/console
  397.  
  398. # If NetWare Networking is desired, start it.
  399.  
  400. ( /usr/bin/niutil -read . /localconfig/NetWare | \
  401.     /usr/bin/egrep 'enable.+YES' ) >/dev/null 2>&1
  402. if [ $? -eq 0 ]; then
  403.     (echo -n "Starting NetWare:")            >/dev/console 2>&1
  404.     # Load and start the kernel server.
  405.     if [ -f /usr/lib/kern_loader/nuc/nuc_reloc ]; then
  406.     /usr/etc/kl_util -a /usr/lib/kern_loader/nuc/nuc_reloc \
  407.         >/tmp/nuc_log 2>&1
  408.     (echo -n ' nuc_reloc ')                >/dev/console 2>&1
  409.     fi
  410.     if [ -f /usr/netware/bin/nucinit ]; then
  411.     /usr/netware/bin/nucinit            >/dev/console 2>&1
  412.     (echo -n ' nucinit')                >/dev/console 2>&1
  413.     fi
  414.  
  415.     # Configure the protocol stack.
  416.     if [ -f /usr/netware/etc/npsd ]; then
  417.     /usr/netware/etc/npsd && (echo -n ' npsd')    >/dev/console 2>&1
  418.     fi
  419.  
  420.     # Start the Management Portal, an internal port for communicating
  421.     # with the kernel server.
  422.     if [ -f /usr/netware/bin/nwmp ]; then
  423.     /usr/netware/bin/nwmp start && (echo -n ' nwmp') >/dev/console 2>&1
  424.     fi
  425.  
  426.     # Start the Netware Service Advertisement Protocol Daemon, which looks for
  427.     # NetWare servers' advertisement packets.
  428.     if [ -f /usr/netware/etc/sapd ]; then
  429.     /usr/netware/etc/sapd && (echo -n ' sapd')    >/dev/console 2>&1
  430.     fi
  431.  
  432.     # Start the NetWare automounter.
  433.     if [ -f /usr/etc/autoNetWaremount ]; then
  434.     /usr/etc/autoNetWaremount && (echo -n ' autoNetWaremount') \
  435.         >/dev/console 2>&1
  436.     fi
  437.     (echo '.')                            >/dev/console
  438. fi
  439.  
  440. # InputManager startup procedure (Japanese)
  441.  
  442. if [ -d /NextLibrary/D8YtManager ]; then
  443.     (echo -n 'Starting input servers:')                >/dev/console
  444.     for i in /NextLibrary/InputManager/*
  445.     do
  446.         if [ -d $i ]; then
  447.             if [ $i = "/Nextlibrary/InputManager/Resources" ]; then
  448.                 continue
  449.             fi
  450.             rcfile=`basename $i`
  451.             if [ -f $i/${rcfile}.rc ]; then
  452.                 sh $i/${rcfile}.rc $1
  453.             fi
  454.         fi
  455.     done
  456.     (echo '.')                            >/dev/console
  457. fi
  458.  
  459. # Any customizations to the startup sequence you would like to make should
  460. # be placed in /etc/rc.local; this way they can be preserved when your 
  461. # system is later upgraded to a new version of system software.
  462.  
  463. if [ -f /etc/rc.local ]; then
  464.     sh /etc/rc.local $1
  465. fi
  466.  
  467. # Unlock tip lines.  tip and UUCP share lock files so they don't get in
  468. # each other's way.
  469.  
  470. if [ -d /usr/spool/uucp ]; then
  471.     rm -f /usr/spool/uucp/LCK.*
  472.     rm -f /usr/spool/uucp/LCK/LCK.*
  473. fi
  474.  
  475. # Start standaard daemons that should always run
  476. (echo -n Starting standard daemons:)                >/dev/console
  477.  
  478. # update flushes the cached blocks from the filesystem using
  479. # the sync system call every 30 seconds.  This ensures the
  480. # disk is reasonably up-to-date in the event of a system crash.
  481.  
  482. update && (echo -n ' update')                    >/dev/console
  483.  
  484. # cron executes commands listed in /etc/crontab at specified times.
  485.  
  486. cron && (echo -n ' cron')                    >/dev/console
  487.  
  488. # accton is here for historical reasons.
  489.  
  490. # if [ -f /usr/adm/acct ]; then
  491. #    accton /usr/adm/acct && (echo -n ' accounting')        >/dev/console
  492. # fi
  493.  
  494. (echo '.')                            >/dev/console
  495.  
  496. # Submit a syslog note to indicate that we've successfully rebooted.
  497. /usr/ucb/logger -t reboot -p kern.crit "$MESSAGE complete"
  498.  
  499. exit 0
  500.