How Linux sets up the service self-startup _linux

Source: Internet
Author: User

Sometimes we need Linux to load certain scripts or system services automatically when the system is powered on.

This is done mainly in three different ways:

ln-s Establish a soft link for the/etc/init.d/service in the/ETC/RC.D/RC*.D directory (* represents one of the seven running levels of 0~6)

chkonfig command line run level setting

Ntsysv Pseudo-graphics run level setting

Note: 1. These three approaches are mainly used in Redhat distributions

2. If you do not know what the operation level is, then it is best to look at the relevant data before the experiment

The first way: Ln-s set up to start soft connections
There are 7 levels of running in Linux (available in/etc/inittab file settings), and each run level corresponds to the 7 directories of/ETC/RC.D/RC[0~6].D

tips:/etc/rc[0~6].d is actually a/etc/rc.d/rc[0~6].d soft connection, primarily to maintain compatibility with UNIX.

In these 7 directories, each directory holds a service that needs to be shut down or started when the run level is loaded.

From the detailed information can be known, in fact, each script file corresponds to the/etc/init.d/directory specific services

The script file at the beginning of K represents the need to close when the run level is loaded, and the representative at the beginning of s needs to perform

So, when we need to start our own script on the boot, just drop the executable script in the/ETC/INIT.D directory, and then create a soft link in the/ETC/RC.D/RC*.D

[Root@localhost ~]# ln-s/etc/init.d/sshd/etc/rc.d/rc3.d/s100ssh

Here sshd is the script file for the specific service, S100SSH is its soft link, S starts at load time

If you need to set up a self-boot at more than one run level, you need to set up multiple soft links

This is a tedious way to apply custom service scripts

If some services already exist on the system (such as the HTTPD service item when you install Apache), you can use the following two ways

The second way: Chkconfig


If you need to start some services yourself, simply use the Chkconfig service name on, and if you want to turn off, change on to OFF

By default, Chkconfig will start 2345 of these four levels, and if you want to customize, you can add the--level option

Let's first turn off all the startup levels for the SSHD service and then start the custom level with the--level option

The tips:--list option to view the startup status of the specified service, Chkconfig View all service statuses without any options

The third Way: Ntsysv pseudo Graphics
Ntsysv and Chkconfig are the same, but they're just adding graphics.

There are two ways to start Ntsysv, one is to enter the NTSYSV directly on the command line, the second is to use the Setup command, and then select System Services

By default, what is the current run level? What is the level of startup service set in Ntsysv, for example, my current run level is 3, then I choose to start the service in the pseudo graphical interface, it will run at 3, if you want to customize the run level to use NTSYSV- Level mode

All of the above three operations require that the service script file be executable, and to have root permissions, where the first way is more custom script, the second to third is more for the system already existing services, such as FTP, samba, SSH, httpd, and so on, and to do the relevant settings need to understand the operational level of the problem

Tips: If you want to start a service manually, the traditional way is to /ETC/INIT.D service name start

You can actually do that,service name start

The above is for you to introduce the three kinds of Linux set up services from the start of the way, I hope to help you learn.

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.