Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the relationship between / etc/rc.d/rc and / etc/rc.d/init.d

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is the relationship between / etc/rc.d/rc and / etc/rc.d/init.d". In daily operation, it is believed that many people have doubts about the relationship between / etc/rc.d/rc and / etc/rc.d/init.d. The editor consulted all kinds of materials and sorted out simple and useful operation methods. I hope it will be helpful to answer the question of "what is the relationship between / etc/rc.d/rc and / etc/rc.d/init.d"! Next, please follow the editor to study!

As mentioned earlier, scripts in the / etc/rc.d/init.d directory are similar to the registry in windows and are executed when the system starts. The program runs here (the init process reads the run level). I believe you can guess from the naming point of view that it is time to run the script in / etc/rc.d/init.d, otherwise why it is also called init (.d), right? Yes, it's time to run the scripts in init.d, but not directly, but selectively, because the system doesn't need to start all the services.

The code is as follows:

[jianbao@localhost rc.d] $pwd

/ etc/rc.d

[jianbao@localhost rc.d] $ll

Drwxr-xr-x. 2 root root 4096 May 2 14:53 init.d

-rwxr-xr-x. 1 root root 2617 June 23 2012 rc

Drwxr-xr-x. 2 root root 4096 May 2 14:53 rc0.d

Drwxr-xr-x. 2 root root 4096 May 2 14:53 rc1.d

Drwxr-xr-x. 2 root root 4096 May 2 14:53 rc2.d

Drwxr-xr-x. 2 root root 4096 May 2 15:35 rc3.d

Drwxr-xr-x. 2 root root 4096 May 2 14:53 rc4.d

Drwxr-xr-x. 2 root root 4096 May 2 14:53 rc5.d

Drwxr-xr-x. 2 root root 4096 May 2 14:53 rc6.d

-rwxr-xr-x. 1 root root 220 June 23 2012 rc.local

-rwxr-xr-x. 1 root root 1970 June 23 2012 rc.sysinit

[jianbao@localhost rc.d] $

So, how does the system choose what needs to be started and what doesn't? At this point, the run level I just mentioned works.

After deciding which run level the system starts, execute the / etc/rc.d/rc script first. In the source code of CentOS6.X, it is check_runlevel () from the very beginning. After knowing the run level, for each run level, there is a subdirectory under rc.d that is rc0.d,rc1.d. .. Rc6.d . Under each directory are links to some of the scripts in the init.d directory. The services to be executed at each level are placed in the corresponding directory. For example, the services to be started at level 5 are all placed under rc5.d, but all the linked files under this rc5.d are linked to the corresponding files in init.d, and the real work is the script in init.d.

The code is as follows:

[jianbao@localhost rc5.d] $pwd

/ etc/rc.d/rc5.d

[jianbao@localhost rc5.d] $ll

Lrwxrwxrwx. 1 root root 16 April 11 14:52 K01smartd->.. / init.d/smartd

Lrwxrwxrwx. 1 root root 17 April 11 14:40 K02oddjobd->.. / init.d/oddjobd

Lrwxrwxrwx. 1 root root 17 April 11 14:52 K05wdaemon->.. / init.d/wdaemon

Lrwxrwxrwx. 1 root root 16 April 11 14:52 K10psacct->.. / init.d/psacct

Lrwxrwxrwx. 1 root root 19 April 11 14:40 K10saslauthd->.. / init.d/saslauthd

Lrwxrwxrwx. 1 root root 15 April 11 14:40 K15httpd->.. / init.d/httpd

Lrwxrwxrwx. 1 root root 13 April 11 14:44 K60nfs->.. / init.d/nfs

Lrwxrwxrwx. 1 root root 20 April 11 14:44 K69rpcsvcgssd->.. / init.d/rpcsvcgssd

Lrwxrwxrwx. 1 root root 16 April 11 14:55 K73ypbind->.. / init.d/ypbind

Lrwxrwxrwx. 1 root root 14 April 11 15:11 K74ntpd->.. / init.d/ntpd

Lrwxrwxrwx. 1 root root 17 April 11 14:40 K75ntpdate->.. / init.d/ntpdate

Lrwxrwxrwx. 1 root root 24 April 11 14:40 S23NetworkManager->.. / init.d/NetworkManager

Lrwxrwxrwx. 1 root root 21 April 11 16:27 S30vboxadd-x11->.. / init.d/vboxadd-x11

Lrwxrwxrwx. 1 root root 25 April 11 16:27 S35vboxadd-service->.. / init.d/vboxadd-service

Lrwxrwxrwx. 1 root root 19 April 11 14:49 S50bluetooth->.. / init.d/bluetooth

Lrwxrwxrwx. 1 root root 14 April 11 14:52 S55sshd->.. / init.d/sshd

Lrwxrwxrwx. 1 root root 13 April 11 14:39 S95atd->.. / init.d/atd

Lrwxrwxrwx. 1 root root 15 May 2 14:53 S95jexec->.. / init.d/jexec

Lrwxrwxrwx. 1 root root 20 April 11 14:40 S99certmonger->.. / init.d/certmonger

Lrwxrwxrwx. 1 root root 11 April 11 14:39 S99local->.. / rc.local

[jianbao@localhost rc5.d] $

At this point, it may be clear to all of you, and I thought it was like this at first. But later, after I carefully looked at and compared these link files with the names of the scripts that were actually executed in init.d, there were several issues that I didn't understand. Taking the opportunity to write this article, I did some homework and finally solved those doubts.

1. Why are these linked files preceded by a Kxx or Sxx?

The thing is, K means to stop (Kill) a service, and S means to Start.

2. What about the numbers followed by K and S? What's it for?

At the beginning, I thought it would look good or count (isn't it childish?) . Turns out it wasn't. Its function is to sort, that is, to determine the order in which these scripts are executed, those with small values are executed first, and those with large values are executed later. In many cases, the order of execution is very important, for example, to start the Apache service, you must first configure the network interface, otherwise it would be funny for a machine without IP to start the http service.

3. Inadvertently, I found that the same service with S and K links to init.d is the same script. I wonder, why execute the same script?

At this time, it is really the wonderful use of S and K, it turns out that S and K are not just used to look clear. S and K also pass parameters of start and stop to the script under init.d, respectively. Oh, it's like this (the look of enlightenment, hehe)! It was then that I remembered the countless / etc/rc.d/init.d/network restart commands I had used before. It turns out that passing S is equivalent to executing the command / etc/rc.d/init.d/xxx start, and of course K is equivalent to / etc/rc.d/init.d/xxx stop.

Add: rc.local can also be modified for self-startup, but rc.local is the last self-startup configuration file to be executed.

At this point, the study of "what is the relationship between / etc/rc.d/rc and / etc/rc.d/init.d" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report