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

The Linux functions script file

This script file provides initial setup features, then provides functions made available to the calling script files.

  1. On lines 11 and 12, a default path is set and exported to the system.
  2. On lines 15 and 16, the screen width variable "COLUMNS" is set to 80 if it has not already been set.
  3. Lines 18 through 34 set the system configuration colors and parameters for bootup, by trying to use the values in the file "/etc/sysconfig/init" (see listing below). If this file, can't be loaded it uses defaults in lines 23 through 32.
    # color => new RH6.0 bootup
    # verbose => old-style bootup
    # anything else => new style bootup without ANSI colors or positioning
    BOOTUP=color
    # column to start "[  OK  ]" label in 
    RES_COL=60
    # terminal sequence to move to that column. You could change this
    # to something like "tput hpa ${RES_COL}" if your terminal supports it
    MOVE_TO_COL="echo -en \\033[300C\\033[$[${COLUMNS}-${RES_COL}]D"
    # terminal sequence to set color to a 'success' color (currently: green)
    SETCOLOR_SUCCESS="echo -en \\033[1;32m"
    # terminal sequence to set color to a 'failure' color (currently: red)
    SETCOLOR_FAILURE="echo -en \\033[1;31m"
    # terminal sequence to set color to a 'warning' color (currently: yellow)
    SETCOLOR_WARNING="echo -en \\033[1;33m"
    # terminal sequence to reset to the default color.
    SETCOLOR_NORMAL="echo -en \\033[0;39m"
    # default kernel loglevel on boot (syslog will reset this)
    LOGLEVEL=1
    
  4. On lines 36 through 40 of the functions file, if the bootup is not to be verbose, the INIT_ARGS string is set to "-q", else it is cleared.
  5. On lines 42 through 79 the "daemon" startup function is listed.
    1. On lines 46 through 60 is a case statement that pre-processes the command line arguments provided to this function.
    2. On lines 47 and 48, the usage for this function is echoed to the user and the function exits if no arguments are provided to this function.
    3. On lines 49 through 55, if this is a check, a command line shift (See shift under the bash man page for builtins)is used to help set the variable "base" to the name of the program to start. The scheduling priority is set to 0 where 20 is the highest priority and 19 is the lowest priority.
    4. On line 57 and 58, the scheduling priority is setup from the command line and a shift is done to be ready to get the file name.
    5. On line 59, the scheduling priority is set to a default of 0.
    6. On line 63, if no base variable was set, the base name is set to the first value on the command line (which due to shifts in the case statement above, may be the second or third value). The program "basename" is used to strip the directory and suffix information from the name of the file to be run.
    7. On lines 66 and 67, a test is done using the "pidofproc" function from this script file to see if the program is already running and if it is, the "daemon" procedure exits.
    8. On line 71 the bash builtin function "ulimit" is used to prevent and date from being written to core files.
    9. On lines 77 and 78 (which are actually one line) the deamon is run using the program "nice" to set the scheduling priority and "initlog" so that events while running it are logged. Note, the c command used to make "initlog" execute the program. Also the function "success" or "failure" is used to log the success or failure of the attempt to the system logger and the screen if the boot is set for verbose mode.
  6. On lines 81 through 138 the "killproc" function is listed.
    1. On lines 83 through 87, if there are no arguments passed on the command line, the procedure echoes proper syntax to the user and exits.
    2. On lines 89 through 96, the kill level of the program is read from the second argument of the command line if it exists.
    3. On line 99, the variable "base" is set to the value of the filename, without directory and suffix information.
    4. On line 102, the process identifier of the program to be killed is read.
    5. On lines 107 through 122, if the kill level was not set, several attempts are made to kill the program. These include using the program "kill" to send the TERM signal, sleeping for 0.1 seconds, then sleep for 1 sec, then sleep for 3 seconds, then try to kill the program using the KILL signal. On line 122, success or failure is reported.
    6. On lines 125 through 129, if the kill level was set, the kill level is sent to the process ID using the bash builtin "kill". Results of failure or success are reported using the functions "failure" or "success".
    7. On line 130 through 132, if no pid was found on line 102, program shutdown failure is reported.
    8. On lines 134 through 137, if there is a pid file left, it is deleted.
  7. On lines 140 through 169, the function to find the process id of a program is listed.
    1. Lines 143 through 146 are used to test syntax and report proper usage if necessary.
    2. Lines 148 through 155 are used to look for the ".pid" file in the "/var/run" directory and if found, echo its value. The program "head" is used to get the first part of the files (Type "man head" for more information).
    3. On lines 157 through 162, the program "pidof" is used to try to find the process ID if the previous attempt failed.
    4. Lines 164 through 168 attempt to extract the process ID using the program "ps" if all other attempts failed.
  8. On lines 171 through 209, the "status" procedure is listed. This function uses the program "pidof" then "ps" then looks in the directory "/var/run" to determine if the program name passed on the command line is running. It then echoes that the program is running if the program "pidof" or "ps" found the program. If the program is found in the directory "var/run" it echoes that the process is dead but the ".pid" file exists. If the process is found in the subdirectory "/var/lock/subsys" it echoes that the process is dead but the subsys is locked. If not found it echoes that the process is stopped.
  9. The echo_success function is listed on lines 211 through 219. It echoes an "OK" to the location specified by the variable "MOVE_TO_COL" in the color "SETCOLOR_SUCCESS". The variable "SETCOLOR_NORMAL" is used to make the last bracket a normal color and restore the normal color.
  10. The echo_failure function is listed on lines 221 through 229. It echoes a "FAILED" to the location specified by the variable "MOVE_TO_COL" in the color "SETCOLOR_FAILURE". The variable "SETCOLOR_NORMAL" is used to make the last bracket a normal color and restore the normal color.
  11. The echo_passed function is listed on lines 231 through 239. It echoes a "PASSED" to the location specified by the variable "MOVE_TO_COL" in the color "SETCOLOR_WARNING". The variable "SETCOLOR_NORMAL" is used to make the last bracket a normal color and restore the normal color.
  12. The success function is listed on lines 241 through 250. It is used to log messages to the system logger. Type "man initlog" for more information. If the bootup is verbose, the failure status is sent to the screen.
  13. The failure function is listed on lines 252 through 262. It is used to log messages to the system logger. Type "man initlog" for more information. If the bootup is verbose, the failure status is sent to the screen.
  14. The passed function is listed on lines 264 through 274. It is used to log messages to the system logger. Type "man initlog" for more information. If the bootup is verbose, the failure status is sent to the screen.
  15. The action function is listed on lines 276 through 285. It is used to run a program using the "initlog" "-r" option and log messages to the system logger. Type "man initlog" for more information.
  16. The confirm function is listed on lines 287 through 304 and us used to verify whether the user wants to run that service.