Previous Page | Next Page

  1. Introduction
  2. Boot Process
  3. Init and System Initialization
  4. rc.sysinit script
  5. rc script
  6. functions script
  7. Services
  8. apm daemon
  9. network startup
  10. The network script file
  11. The network-functions file
  12. Portmap startup
  13. Random initialization
  14. Syslog initialization
  15. Gated
  16. Atd
  17. cron initialization
  18. pcmcia
  19. inetd daemon
  20. named daemon
  21. lpd daemon
  22. mars-nwe
  23. netfs startup
  24. dhcpd daemon
  25. autofs daemon
  26. keytable daemon
  27. sendmail daemon
  28. gpm daemon
  29. httpd daemon
  30. xfs startup
  31. smb startup
  32. innd startup
  33. linuxconf startup
  34. rc.local script
  35. Init, Getty, Login
  36. The shell
  37. Shutting down
  38. X
  39. Conclusions
  40. App A. rc.sysinit listing
  41. App B. functions listing
  42. App C. rc listing
  43. Credits

Linux rc script

The script file /etc/rc.d/rc (See Appendix C) is run for the appropriate runlevel (typically 3) This file does the following:

  1. On line 13, it makes the functions in the "/etc/rc.d/init.d/functions" file available
  2. On line 16, it sets the variable "argv1" to the runlevel numeric value passed on the command line.
  3. On line 17, it runs the program "runlevel" to get the previous and current system runlevels. Type "man runlevel" for more information. The variables "runlevel" and "previous" are set to the appropriate returned values and exported on lines 17-20.
  4. On lines 22-29, it sets the variable "CONFIRM" to yes if the word confirm is in the file "/proc/cmdline" or the file "/tmp/confirm" exists.. This is used later for user confirmation for each service to be run.
  5. On line 32, if the current runlevel is not set, it sets the variable "runlevel" to the value passed on the command line.
  6. On line 35, if the directory "/var/run" exists the text "/etc/rc.d/rc3.d" is copied into the file "/var/run/runlevel.dir" where 3 is the runlevel we are in.
  7. On line 38, if the directory "/etc/rc.d/rc3.d" exists the following functions will be performed. If it does not, the script file will end. Note: The directory "/etc/rd.c/rc3.d" is specified as an example for runlevel 3.
  8. On line 40, a do loop is started that will run the variable I through the name of all files in the subdirectory "/etc/rc.d/rc3.d" (assuming runlevel 3) that begin with "K".
  9. On line 42, if the script file, for the variable I does not exist, it continues to the next attempt. This could be to allow exit if there are no kill files in the directory.
  10. Lines 45-47 utilize parameter expansion as talked about in the bash man page. On each line, if there is no match the expanded pattern will be the name of the script file which is the variable I. If it matches the pattern will include ".rpmsave" at the end for example. If there is a match on line 45 the original value may have been, "/etc/rc.d/rc3.d/K20rstatd.rpmsave", therefore the value on the left would be "/etc/rc.d/rc3.d/K20rstatd" and the value on the right would be "/etc/rc.d/rc3.d/K20rstatd.rpmsave" (the original value). Therefore in the "!=" compare there would be no match and the continue statement would allow the do loop to proceed to the next iteration of the variable I. If there was not a match on line 45, the original value may have been "/etc/rc.d/rc3.d/K20rstatd", and the value on the left and right would be "/etc/rc.d/rc3.d/K20rstatd", the same as the original value. This is because with parameter expansion, it there is no match, the expansion stays the same as the original value (I think).
  11. On line 50, parameter expansion is used to set the variable "subsys" to "rstatd" in our example above. This is because the shortest match between the variable I and "/etc/rc.d/rc3.d/K??" is removed from the string and only the rest is kept. The value of I is "/etc/rc.d/rc3.d/K20rstatd". The matching portion is "/etc/rc.d/rc3.d/K20". The part after the match is kept which is "rstatd".
  12. Lines 51 and 52 are one line as far as the shell is concerned because of the "\" character at the end of line 51. This line tells the shell to continue to the next iteration of the variable I, if the file "/var/lock/subsys/rstatd" does not exist and the file "/var/lock/subsys/rstatd.init" does not exist in our example. I think shutting down was skipped since the system was not up unless one of these two files exist.
  13. On lines 55 through 59, if the words "killproc" or "action" are found in the script file "/etc/rc.d/rc3.d/K20rstatd" then the link file "/etc/rc.d/rc3.d/K20rstatd" is invoked with the parameter "stop" passed on the command line. This link file points to the script file "/etc/rc.d/init.d/rstatd" which is run with "stop" on the command line. This will cause this service to stop. If the words "killproc" or "action" were not found then the subsystem is stopped using the function "action" from the file "/etc/rc.d/init.d/functions". Note: the script file "etc/rc.d/init.d/functions" and the start/stop script files ("/etc/rc.d/init.d/rstatd" in our example) will be discussed later.
  14. On lines 63 through 104 the startup scripts are run in much the same manner as the kill scripts. Lines 63 through 73 are the same, except the letter "S" is used where "K" was used in steps 8 through 11, above. Further differences are noted below.
  15. On lines 74 and 75 compared to step 12 above, the if statement is made an "or" statement rather than an "and" statement so if the subsystem is up or being brought up, we will not start it here.
  16. In lines 77 through 92, if we are in confirmation mode as in step 4 above, we use the "confirm" procedure in the "/etc/rc.d/init.d/functions" file to verify that the user wants to run this subsystem.
  17. Lines 94 through 103 are similar to step 13 above.

For my Redhat 6.0 system, the following files exist in the directory "/etc/rc.d/rc3.d":

total 887
drwxr-xr-x   2 root     root         1024 Sep  1 15:02 .
drwxr-xr-x  10 root     root         1024 Aug 16 05:47 ..
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 K08autofs -> ../init.d/autofs
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 K10xntpd -> ../init.d/xntpd
lrwxrwxrwx   1 root     root           20 Aug 16 06:15 K15postgresql -> ../init.d/postgresql
lrwxrwxrwx   1 root     root           20 Aug 16 06:15 K20bootparamd -> ../init.d/bootparamd
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 K20rstatd -> ../init.d/rstatd
lrwxrwxrwx   1 root     root           17 Aug 16 06:15 K20rusersd -> ../init.d/rusersd
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 K20rwalld -> ../init.d/rwalld
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 K20rwhod -> ../init.d/rwhod
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 K25squid -> ../init.d/squid
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 K30mcserv -> ../init.d/mcserv
lrwxrwxrwx   1 root     root           19 Aug 16 06:15 K34yppasswdd -> ../init.d/yppasswdd
lrwxrwxrwx   1 root     root           18 Aug 16 06:15 K45arpwatch -> ../init.d/arpwatch
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 K50snmpd -> ../init.d/snmpd
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 K55routed -> ../init.d/routed
lrwxrwxrwx   1 root     root           14 Aug 16 06:15 K80nscd -> ../init.d/nscd
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 K88ypserv -> ../init.d/ypserv
lrwxrwxrwx   1 root     root           14 Aug 16 06:15 S05apmd -> ../init.d/apmd
lrwxrwxrwx   1 root     root           17 Aug 16 06:15 S10network -> ../init.d/network
lrwxrwxrwx   1 root     root           17 Aug 16 06:15 S11portmap -> ../init.d/portmap
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 S15netfs -> ../init.d/netfs
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 S20random -> ../init.d/random
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 S30syslog -> ../init.d/syslog
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 S32gated -> ../init.d/gated
lrwxrwxrwx   1 root     root           13 Aug 16 06:15 S40atd -> ../init.d/atd
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 S40crond -> ../init.d/crond
lrwxrwxrwx   1 root     root           16 Aug 16 06:15 S45pcmcia -> ../init.d/pcmcia
lrwxrwxrwx   1 root     root           14 Aug 16 06:15 S50inet -> ../init.d/inet
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 S55named -> ../init.d/named
lrwxrwxrwx   1 root     root           13 Aug 16 06:15 S60lpd -> ../init.d/lpd
lrwxrwxrwx   1 root     root           18 Aug 16 06:15 S60mars-nwe -> ../init.d/mars-nwe
lrwxrwxrwx   1 root     root           13 Aug 16 06:15 S60nfs -> ../init.d/nfs
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 S65dhcpd -> ../init.d/dhcpd
lrwxrwxrwx   1 root     root           13 Aug 16 06:15 S72amd -> ../init.d/amd
lrwxrwxrwx   1 root     root           18 Aug 16 06:15 S75keytable -> ../init.d/keytable
lrwxrwxrwx   1 root     root           18 Aug 16 06:15 S80sendmail -> ../init.d/sendmail
lrwxrwxrwx   1 root     root           13 Aug 16 06:15 S85gpm -> ../init.d/gpm
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 S85httpd -> ../init.d/httpd
lrwxrwxrwx   1 root     root           15 Aug 16 06:15 S85sound -> ../init.d/sound
lrwxrwxrwx   1 root     root           13 Aug 16 05:37 S90xfs -> ../init.d/xfs
lrwxrwxrwx   1 root     root           13 Aug 16 06:15 S91smb -> ../init.d/smb
lrwxrwxrwx   1 root     root           14 Aug 16 06:15 S95innd -> ../init.d/innd
lrwxrwxrwx   1 root     root           19 Aug 16 06:15 S99linuxconf -> ../init.d/linuxconf
lrwxrwxrwx   1 root     root           11 Aug 16 05:36 S99local -> ../rc.local
-rw-------   1 root     root       901120 Sep  1 12:09 core
-rw-r--r--   1 root     root            0 Sep  1 15:02 list

The files listed above indicate the subsystems that are not to be run for this runlevel (if they are in a file that begins with the letter "K") and the subsystems that are to be run for this runlevel (if they are in a file that begins with the letter "S"). Note near the bottom of the list is a file called "S99local" which is run after all the other scripts. We will discuss this script later. First, we'll analyze an example startup/shutdown file. Also note the numeric listing "Sxxrstatd". Since the files are run in alphabetic order when the kill and startup portions of the script file "/etc/rcd/rc" are run, the relative value of the number after the first character determines the relative order it will be run in.. Remember in steps 13 and steps 17 above the word stop or start was passed on the command line to these link files. Usually the startup and kill file will link to the same file, which is used both to start a subsystem and stop it. This file should be found in the directory "/etc/rc.d/init.d" as indicated by its link information. The next section lists a typical file for starting samba services, "/etc/rc.d/init.d/smb".