/Etc/rc. d/init. d and/etc/init. d

Source: Internet
Author: User
$ LS-LD/etc/rc. d
Drwxr-XR-x 10 Root 352 February 13 13:38/etc/rc. d/
$ LS-LD/etc/init. d
Lrwxrwxrwx 1 Root 11 February 13 13:38/etc/init. d-> rc. d/init. d/
One is another soft link.
Etc/rc. d/init. D contains some scripts for the INIT process (that is, process 1) to choose to run init according to the startup running level obtained by the process during initialization. d. These are the software installed in the system.
The running level determines the level at which the system runs after startup. This level ranges from 0 to 6 and has different functions. The downtime level is 0, and the restart level is 6.
The value is obtained by the initdefault id value in the inittab file in the/etc/directory from the INIT process.
Generally, the runtime level of the X11 graphic interface in Linux is 5.
Normally, RC means run control.
View/etc/inittab
#
# Inittab this file describes how the INIT process shocould set up
# The system in a certain run-level.
#
# Author: Miquel van smoorenburg <miquels@drinkel.nl.mugnet.org>
# Modified for RHS Linux by Marc Ewing and Donnie Barnes
#
# Default runlevel. The runlevels used by RHS are:
#0-halt (do not set initdefault to this)
#1-Single User Mode
#2-multiuser, without NFS (the same as 3, if you do not have networking)
#3-full multiuser Mode
#4-unused
#5-X11
#6-Reboot (do not set initdefault to this)
#
ID: 5: initdefault:
# System initialization.
Si: sysinit:/etc/rc. d/rc. sysinit
L0: 0: Wait:/etc/rc. d/RC 0
L1: 1: Wait:/etc/rc. d/RC 1
L2: 2: Wait:/etc/rc. d/RC 2
L3: 3: Wait:/etc/rc. d/RC 3
L4: 4: Wait:/etc/rc. d/RC 4
L5: 5: Wait:/etc/rc. d/RC 5
L6: 6: Wait:/etc/rc. d/RC 6
The red part specifies the running level. 5 is in X11 mode, which is imported into the graphic interface. 1 is the character interface.
Call the commands in/etc/rc. d/rcX. d/corresponding to each level.
For example, Level 5 calls/etc/rc. the commands in D/rc5.d/, in which the S header represents the commands run during start, and the K header represents the commands run during shutdown.
A small number is executed before a large number, for example, s01sysstat is executed before s05kudzu.
The command in/etc/init. d should be the link used by the command in/etc/rc. d/rcX. d.

From http://hi.baidu.com/fwind1/blog/item/24bf6e0279c6a00e738da5c1.html

/Etc/init. d points to the/etc/rc. d/init. d directory

Linux/etc/rc. d/directory details

The content of rc. d is as follows:
Init. d/: directory for storing binary files of various servers and programs.
RcX. d/: directory for connecting execution programs at various startup levels. Everything in it is a soft connection pointing to init. d. The details are described later.
There are three other scripts: RC. sysinit, RC, RC. Local

The RedHat Startup Mode and execution sequence are as follows:
Load the kernel
Run the INIT program
/Etc/rc. d/rc. sysinit # The first script executed by init
/Etc/rc. d/RC $ runlevel # $ runlevel is the default running mode.
/Etc/rc. d/rc. Local
/Sbin/mingetty # Wait for User Login

In RedHat,/etc/rc. d/rc. sysinit mainly performs the same initialization in each running mode, including:
Incoming keymap and system font
Start swapping
Set Host Name
Set the NIS domain name
Check (fsck) and mount the File System
Open quota
Mount sound card module
Set system clock
And so on.

/Etc/rc. d/RC executes scripts in the corresponding directory according to the running mode specified by its parameters (the running level, which can be set in the inittab file. All parameters starting with kxx are called with the Stop parameter. All parameters starting with sxx are called with the start parameter. The call sequence is from xx to xx. For example, if the default running mode is 3,/etc/rc. d/RC will call the script in/etc/rc. d/rc3.d/as described above.
It is worth mentioning that the operating modes 2, 3, and 5 in RedHat put/etc/rc. d/RC. local is the last in the initialization script, so you can add some commands that need to be executed before logging on to this file.

Init is waiting for/etc/rc. d/RC after execution (because/etc/inittab/etc/rc. d/RC's action is wait). It will run/sbin/mingetty on each specified virtual terminal and wait for the user to log on.
So far, the Linux Startup has ended.

Finally, I want to add some:

1. Many network services are started by the Super Service/etc/rc. d/init. d/xinetd. The configuration files of these services are in the/etc/xinetd. d/directory,

For example, telnet is started by xinetd. The configuration file is as follows (fc7)

1 # default: On
2 # Description: the telnet server serves Telnet sessions; it uses \
3 # unencrypted username/password pairs for authentication.
4 service telnet
5 {
6 flags = Reuse
7 socket_type = stream
8 wait = No
9 user = root
10 Server =/usr/sbin/in. telnetd
11 log_on_failure + = userid
12 disable = No
13}
After modifying the configuration file, restart the xinetd service.

2. In addition to directly calling scripts (such as/etc/rc. d/init. d/xinetd), you can also use the service command to control the services under the init. d directory,

Such as service xinetd restart,

From http://hi.baidu.com/ueszx/blog/item/93d4e3f0de6d02ce7831aa61.html

/Etc/rc. d/relationship with/etc/rc. d/init. d)

Here, I will explain what is put in init. d. This directory stores some scripts, which are generally the startup scripts of some services set during the installation of RPM packages in Linux. The system has installed many rpm packages, and there are many corresponding scripts. Run these scripts to start, stop, and restart these services.
As mentioned above, the script in the directory/etc/rc. d/init. d is similar to the Registry in windows and executed when the system is started. The program runs here (the INIT process reads the running level). From the perspective of naming, you can also guess how to run/etc/rc. d/init. d. Why is it also called Init (. d) Right. Yes, it is time to run the script in init. d, but it is not a direct operation, but an alternative because the system does not need to start all services.
Then, how does the system choose what needs to be started and what does not? At this time, the running level just mentioned takes effect.
After the run level of the system is determined, the script/etc/rc. d/RC is executed first. In the source code of rh9 and fc7, It is check_runlevel () (although the implementation code is different, it is also similar). After knowing the running level, for each running level, it is in RC. there is a subdirectory under D: rc0.d, rc1.d ..... Rc6.d. Each directory contains links to some scripts in the init. d directory. The services to be executed at each level are under the corresponding directory. For example, the services to be started at level 5 are placed under rc5.d, but some link files are put under rc5.d, link to init. d. d.

At this point, it may be clear to everyone. I thought it was like this. However, after carefully reading and comparing these link files and the file names of the scripts actually executed in init. d, I still haven't figured out a few issues. With the opportunity to write this article, I have done some homework and finally solved the doubts.
1. Why does kxx or sxx appear before these linked files?
Yes, K indicates that a service is stopped (kill), and s indicates that start is enabled.
2. What are the numbers behind K and S? What is it?
At the beginning, I thought it was a good arrangement or a good number (isn't it naive ?). Later I found that it was not. It is used to sort the scripts, that is, to determine the execution sequence of these scripts. If the values are small, the scripts are executed first, and the scripts are executed after the values are large. In many cases, the execution sequence is very important. For example, to start the apache service, you must first configure the network interface. Otherwise, it would be funny to start the HTTP service with a machine without an IP address...
3. I accidentally found that the same service with S and link with K to init. d is the same script. I wondered why the same script was executed?
At this time, S and K are really amazing. In the past, S and K are not just used to look clearly divided. S and K respectively pass the start and stop parameters to the script under init. d. Oh, that's it )! Then I remembered the countless/etc/rc. d/init. d/network restart commands that I used. When S is passed, it is equivalent to executing/etc/rc. d/init. d/xxx start command. k is equivalent to/etc/rc. d/init. d/xxx stop.

Supplement: You can also modify RC. Local to achieve self-starting, but RC. Local is the final self-starting configuration file.

From http://blog.sina.com.cn/s/blog_4b0a626701009mak.html

From: http://blog.163.com/fan_yishan/blog/static/4769221320117151727450/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.