English version of this article from: http://www.ghacks.net/2009/04/04/get-to-know-linux-the-etcinitd-directory/
The following is the author's own version of the translation, if you want to reprint to other sites outside CSDN, please indicate this article link.
First, about/ETC/INIT.D
If you have used a Linux system, you must have heard of the INIT.D directory. What the hell is this directory for? It's only done one thing in the end, but it's very important that it's done for the whole system . The INIT.D directory contains many system startup and stop scripts for various services. It controls all kinds of transactions from Acpid to X11-common. Of course, INIT.D is far from being so simple. (Translator Note: Acpid is a new power management standard for Linux operating system; X11 is also called the X Window System, and the X Window System (X11 or X) is a bitmap-display windowing system. It is a standard toolkit and protocol for creating graphical user interfaces on Unix and UNIX-like operating systems, as well as OpenVMS, and can be used in almost any modern operating system.
When you look at the/etc directory, you will find many directories that exist in rc#.d form (where # represents a specified initialization level, and the range is 0~6). Under these directories, there are many scripts that control the process. These scripts either start with "K" or start with "S". A script starting with K runs before a script that begins with S. Where these scripts are placed, will determine when these scripts start running. Between these directories, system services work together, just like a well-functioning machine. However, sometimes you want to be able to start or kill a process cleanly without using the kill or Killall command. This is where/etc/init.d can come in handy!
If you are using the Fedora system, you can find this directory:/etc/rc.d/init.d. In fact, no matter where the INIT.D is placed, it plays the same role.
In order to be able to use scripts under the INIT.D directory, you need to have root or sudo permissions. Each script will be run as a command with a structure that looks similar to the following:
/etc/init.d/command Options
Comand is a command that is actually running, and the options can be as follows:
- Start
- Stop
- Reload
- Restart
- Force-reload
Most of the cases, you will use the Start,stop,restart option. For example, if you want to turn off the network, you can use the following form of command:
/etc/init.d/networking stop
Another example is that you change the network settings and need to restart the network. You can use the following command:
/etc/init.d/networking restart
Common init scripts under the INIT.D directory are:
- Networking
- Samba
- Apache2
- Ftpd
- Sshd
- Dovecot
- Mysql
Of course, you may have more commonly used scripts, depending on what Linux operating system you have installed.
Second, about/etc/rc.local
Rc.local is also a script that I often use. The script is executed after the system initialization level script runs, so you can safely add scripts that you want to execute after the system starts. The common scenario is that you can add NFS mount/mount scripts inside again. In addition, you can also add some debugging script commands. For example, I've come across a situation where samba services always fail to work, and the check finds that Samba is executing during system startup, which means that the Samba daemon configuration ensures that this functionality should be performed correctly. In this similar situation, I usually do not bother to spend a lot of time to find out why, I just need to simply add this line in the/etc/rc.local script:
/etc/init.d/samba start
This successfully solves the problem of samba service anomalies.
Iii. Summary
Linux is flexible. Because of its flexibility, we can always find many different ways to solve the same problem. An example of starting a system service is a good corroboration. With the script in the/ETC/INIT.D directory, plus the/etc/rc.local, you can be assured that your service will be up and running perfectly.
Transferred from: http://blog.csdn.net/acs713/article/details/7322082
Another article:
This article includes 3 parts of the content
1, the Linux boot process
2. Operating level
3. The relationship between/etc/rc.d/and/ETC/RC.D/INIT.D
are limited to their own understanding, if there are errors and deficiencies in the place please correct and add! Learn together and progress together.
"The script in the/etc/rc.d/init.d/directory is similar to the registry in Windows, and some of the specified scripts will be executed when the system starts." Before we begin, I would like to make a general impression on the INIT.D catalogue by quoting an understanding of Li Shanming Manager's summary last night. Before entering INIT.D, let's do two preparations, the Linux boot process and the concept of runlevel.
First, the Linux boot process
After the system starts, before entering the INIT.D, we first look at what the system has done, first look at a diagram (this figure from the network, late to fill up)
From this diagram, we look at the whole process of starting guidance from a higher point of view, which is quite clear.after the system power-up, the first hardware self-test, then the bootloader to the system initialization, load the kernel.
once the kernel is loaded into memory, it starts executing. Once the kernel is up and running,The detection of hardware determines which device drivers need to be initialized. From here, the kernel is able to mount the root filesystem (a process similar to that used by Windows to identify and access C-disk).after the kernel has installed the root filesystem and has initialized all device drivers and data structures, the boot process is completed by launching a user-level program called Init.
Second, RunLevel (run level)
The init process is the first user process after the system starts, so its PID (process number) is always 1. The first thing to do on the INIT process is to read the Initdefault ID value in the Inittab file in the/etc/directory, which is called the RunLevel (Run-level). It determines the level at which the system runs after it is started. The operating level determines most of the behavior and purpose of the system startup. This level is from 0 to 6 and has different functions. The different run-level definitions are as follows:
# 0-Stop (do not set the Initdefault to 0, or the system will never start)
# 1-Single user mode
# 2-Multiuser, no NFS
# 3-Full multi-user mode (standard run level)
# 4– system Reserved
# 5-x11 (x Window)
# 6-Reboot (never set Initdefault to 6, otherwise it will be restarted)
This is the two table more commonly used runlevel (post-fill), left figure Redhat9 level 3 will be the text interface, the right figure Fc7 level 5 will start the graphical interface.
Three, the relationship between/etc/rc.d/and/ETC/RC.D/INIT.D
Write here, should be almost to enter the INIT.D, but I think that/etc/rc.d/init.d words can not be able to say clearly understand, take it and/etc/rc.d this it on the first level of the directory together to discuss, may be more appropriate, because they have countless relationships.
Here, let's explain what's in the INIT.D.This directory contains scripts that are typically startup scripts for some of the services that Linux has set up to install with RPM packages. The system is installed in a lot of RPM packages, where there are many corresponding scripts. Executing these scripts can be used to start, stop, and restart these services.
As mentioned earlier, the/ETC/RC.D/INIT.D script in this directory is similar to the registry in Windows, which executes when the system starts. The program runs here (the Init process reads the runlevel), and I believe that from a named point of view you can guess the script that runs/ETC/RC.D/INIT.D, or why it's also called Init (. D). Yes, it's time to run the script in INIT.D.but not directly, but selectively, because the system does not need to start all services.
So, how does the system choose which needs to start and what not? At this point, the level of operation that was just said worked.after the system-initiated run level is determined, the/ETC/RC.D/RC script executes first. In the source code of RH9 and FC7 it is a check_runlevel () (although the implementation of the code is not the same, but also the same), knowing the RunLevel, for each run level,under RC.D, there is a subdirectory rc0.d,rc1.d ... rc6.d. Each directory is a subset of the scripts to the INIT.D directory for some links. Each level to perform which services in the corresponding directory, such as Level 5 to start the service is placed under RC5.D, but placed under this rc5.d are some link files, link to init.d in the corresponding file, really work to INIT.D script.
Redhat9 ls
Fc7 ls-l
So it's clear to see.
Here, I think everyone may be more clear, I began to believe that this is the case. But then I looked closely and compared the filenames of these linked files and the scripts that were actually executed in the INIT.D, and there were a few questions that didn't make sense. By the chance to write this article, I have done some homework, and finally I have probably solved the doubts.
1. Why do these linked files bring a kxx or sxx?
Yes, with the K-Stop (Kill) a service, s means to open (start)
2, K and s behind the number? What's the use?
I thought it was a good arrangement or counting. Later found not. It is used to sort, that is, to determine the order of execution of these scripts, the value of small first execution, the value of large after execution. Most of the time these execution order is very important, such as to start the Apache service, you must first configure the network interface, or a non-IP machine to start the HTTP service it is not very funny ...
3, inadvertently I found the same service with S and with k link to Init.d is the same script. I wonder why the same script is executed?
This time is really the magic of S and K, the original S and K and not only for the look of the clear. s give and K are also passed the start and stop parameters to the script below Init.d. Oh, that's it (Huanran dawu look, hehe)! Then I think of the original once countless used/etc/rc.d/init.d/network restart command. The original transmission S is equivalent to the execution of/etc/rc.d/init.d/xxx start this command, of course, K is equivalent to/etc/rc.d/init.d/xxx stop
Transferred from: http://blog.csdn.net/r91987/article/details/7625411
Understanding Linux System/ETC/INIT.D directories and/etc/rc.local scripts