Overview of Linux Boot Services

        Seven operating levels are defined in traditional linux, as follows: Levels 1 and
        0 are the levels for completely shutting down the system.
        Level 2, 1 or S stands for single-user mode, which closes all multi-user and remote login processes.
        3. Levels 2--5 are multi-user levels.
        Levels 4 and 6 are "multiboot" levels.
        Among them, level 0 and level 6 cannot make the system stay, and the effect of entering these two levels is to shut down the system or reboot the system. On most systems, the normal multi-user runlevels are 2 or 3, runlevel 5 is often used for X Windows login processes, runlevel 4 is rarely used, and runlevels 1 and S are defined differently on each system of.
        The services running under each run level are different. /etc/inittab specifies the commands to be run when the system enters each level. When the machine boots, init starts at runlevel 0 and works its way up to the default runlevel set in /etc/inittab. When the machine is turned off, the same process is performed in reverse order.
        However, for more flexibility, linux usually takes the form of a "change runlevel" script, called by inittab. This script then executes other scripts located in the directory associated with the runlevel to bring the system to the new state.
        Master copies of startup scripts are located in the /etc/init.d/ directory, and each script is responsible for a daemon or a specific aspect of the system. For the convenience of management, these scripts can accept parameters start and stop, and most of them also accept restart, so that the corresponding service can be started or stopped quickly. For example, the following startup script can start, stop or restart the sshd service:
#!/bin/sh

test -f /usr/bin/sshd || exit 0
case "$1" in
    start)
        echo "Starting sshd."
        /usr/sbin/sshd
        ;;
    stop)
        echo "Stopping sshd."
        kill `cat /var/run/sshd.pid`
        ;;
    restart)
        echo "Stopping sshd."
        kill `cat /var/run/sshd.pid`
        echo "Starting sshd"
        /usr/sbin/sshd
        ;;
    *)
        echo "Usage: /etc/init.d/sshd start|stop|restart"
        exit 1
        ;;
esac

        Although the scripts in /etc/init.d/ can start and stop various services, the main control script run by init needs to know some other information about which scripts need to be run to enter any given runlevel. To simplify the operation, when the main script introduces the system to a new run level, it does not look directly in the init.d directory, but in a directory called /etc/rcLEVEL.d/, where LEVEL is to be entered Runlevel number (eg rc0.d, rc1.d, etc.). These /etc/rcLEVEL.d/ directories contain symbolic links to services in the /etc/init.d/ directory, all of which have names beginning with S or K followed by a number and the name of the service controlled by the script ( For example, S55sshd, etc.). When init transitions from a low run level to a high run level, it runs all scripts with the start parameter starting with S (for start) in increasing numerical order; when init runs from a high run level to a low run level When a level transitions, it runs all scripts with a stop parameter starting with K (for kill) in decreasing numerical order.
        This mechanism gives system administrators fine-grained control over the order in which services are started. So be sure to take this dependency into account when adding new services. To tell the system when to start a daemon, we must create a symbolic link in the appropriate directory. For example, to tell the system to start CUPS during runlevel 2 and to gracefully stop the daemon before the system shuts down, it would suffice to create the following pair of links (some systems handle system shutdown and reboot differently, so maybe A symbolic link needs to be placed in the /etc/rc6.d/ directory as well to ensure the daemon is shut down properly when the system reboots):
          # ln -s /etc/init.d/cups /etc/rc2. d/S80cups
          # ln -s /etc/init.d/cups /etc/rc2.d/K80cups
        For both Red Hat and Fedora, init calls the script /etc/rc.d/rc with the runlevel as an argument. /etc/rc.d/rc normally runs in "normal" mode, where it just does its own thing. It can also run in "confirm" mode, where it will ask the user before running each individual startup script. Red Hat and Fedora have a chkconfig command to help users manage services. This command can add or delete startup scripts on the system, manage the priority of execution of these scripts, and list which runlevels a script is currently configured for. Red Hat also has an rc.lacal script, the last script that runs as part of the startup process, to which users can add their own custom startup content. Most configuration of the Red Hat boot process should be done by manipulating the configuration files in /etc/sysconfig. The following table summarizes the functions of some of the entries in the /etc/sysconfig directory:
File Directory function or content
clock Specifies the type of clock the system has (almost always UTC)
console A mysterious directory that is always empty
httpd Decide which processing mode to use with Apache
hwconf Contains all information on system hardware, used by Kudzu
i18n Contains the system's local settings (date format, language, etc.)
init Configure how messages from startup scripts are displayed
keyboard Set the keyboard type (use us for a standard 101-key US keyboard)
mouse Set the mouse type, used by X and gpm
network Set global network parameters (hostname, gateway, forwarding mechanism, etc.)
network-scripts Directory containing supplementary scripts and network configuration files
sendmail Set options for sendmail


Reference material: "Linux System Management Technical Manual" Chapter 2 - Boot and Shutdown.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326242680&siteId=291194637