Ubuntu running level, boot script description, ubuntu script

Source: Internet
Author: User

Ubuntu running level, boot script description, ubuntu script

Description of Ubuntu running level and startup script

Directory Overview

1.1 introduce the Ubuntu Script directory

1.2 concept of Linux operating system running level

1.3 startup sequence of operating system self-starting scripts

1.4 concept of Linux operating system running level

1.5 enable and disable the service

1.6 for the init [number] command

Content:

1.1 introduce the Ubuntu operating system's self-starting script directories

Here, rc0.d ~ The rc.6.d folder corresponds to the scripts to be executed when the operating system is running at level 0 to 6. In addition, there are the rc. d folder and rc. local files, and the files in these folders are soft chain files, pointing to the script at the specified location, as shown in the following figure:

After checking, we found that these soft links all point to the script file of the same folder ../init. d,

We checked other folders and found that the situation was like this. Therefore, all the script files starting from startup are stored in the/etc/init. d/directory:

 

So what does rcN. d mean? Or is it based on 0 ~ 6 In sequence? Certainly not. Because we can view rc0.d folder

It is found that there is an halt (shutdown) script in this folder. Therefore, it is certainly impossible to execute this script when the operating system is enabled. Therefore, it is proved that the folders rcN. d are independent of each other and there is no essential link between them.

So why are there differences between these folders? This introduces the run-level concept of the linux operating system.

1.2 concept of Linux operating system running level

Based on the previous content, we know that rc0 ~ 6. Add the rc. d & rc. local. We will not see the two later. There are at least seven running levels from 0 to 6. The concept of running level is called the running mechanism of System V. The meanings of these seven running levels are as follows (for Ubuntu only, the definitions of other systems may be different ):

You can use runlevel to view the running status of the current system.

 

 

That is to say our system is currently running level 2, the parameter configuration file/etc/init/rc-sysinit.conf

 

Therefore, the script for auto-start is in the rc2.d folder, and all soft links point to the script file in/etc/init. d:

 

These are the services to be started under the default boot status. If we put our scripts in/etc/init. d/directory, at the same time in rcN. d. Create a soft link and point to the file (the soft link name should be S <num> <service name>, and you can start these services on your own. You can also modify the DEFAULT_RUNLEVEL value in the configuration file/etc/init/rc-sysinit.conf to modify the default operating level of the operating system.

1.3 startup sequence of operating system self-starting scripts

Assuming that the operating system running level is 2, what is the script execution sequence in the/etc/rc2.d/folder? Because some services need to be started first and some services need to be started later, there is a sequential relationship between them, that is, the relationship between Directed Graphs.

Check the soft link name in the folder (see figure). The soft link name has certain rules:

S [number] [service name] --> ../init. d/servicename

S indicates Start, and the service is enabled

[Number] indicates the script running priority. The smaller the number, the higher the script running priority.

[Service name] indicates the service name.

Therefore, if you need to define a priority (sequence) for starting a service, you need to specify the number of the script.

Based on this rule, we can view the rc6.c folder (restart running level ):

In the order of number, the Kill service is displayed, some services are started, and S90reboot is restarted.

1.4 significance of the rc. local folder

The script is in rc0 ~ 6. Run the script command in the. d folder before executing the script.

1.5 enable and disable the service

After understanding the principle of the self-starting service, we can manually add a script to link the file to the specified rcN. d directory, but this manual method is more complex, so we can use simple commands to implement this function, or to implement it using a specified tool.

Command version # update-rc.d to automatically implement the RunLevel STARTUP script service of System V, provided that the startup scripts of these services are located in the/etc/init. d/directory.

Update-rc.d <service name> start | stop | <order number> <run levels>

Eg:

Sudo update-rc.d (rinetd start 20 2)

Sudo update-rc.d rinetd stop 20 0

 

Update-rc.d <service name> enable | disable <runlevels> # enable or disable

Eg:

Sudo update-rc.d rinetd disable 2 temporarily disables this service in runlevel2

 

Update-rc.d <service name> default [NN | ss kk]

Eg:

Sudo update-rc.d rinetd default 80 80 # default represents adding 80 (the first 80) sequence of Start in 2 3 4 5, adding 80 (the second 80) in 0 6) sequential Kill Service

Note that you can view the ordernumber of the Service in the corresponding folder.

Delete from startup

Sudo update-rc.d-f <service name> remove

In this way, the link about the service is deleted from all running levels (only the link is deleted, not the script file in the/etc/init. d/folder)

1.6 for the init [number] command

We disable or restart the operating system in the command line.

 

 

 

Essentially, the following is called:

 

Rc0.d indicates shutting down rc6.d indicates restarting.

Therefore, we can switch the RunLevel of the operating system without restarting the operating system.

Sudo init <num>

GuangZhou 2016-8-6

 

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.