How do I set up service self-booting in Linux?

Source: Internet
Author: User

Turn from: How do I set up service self-booting in Linux?

Sometimes we need the Linux system to automatically load some scripts or system services when booting up, mainly in three ways to do this:

    1. Ln-s a soft link to the/etc/init.d/service in the/ETC/RC.D/RC*.D directory (* represents one of the 0~6 seven RunLevel)
    2. Chkonfig command line Run level settings
    3. NTSYSV pseudo-graphic run level settings

Attention:

    1. These three methods are primarily used in Redhat-based distributions
    2. If you don't know what the runlevel is, it's best to take a look at the relevant data before you experiment.

The first way: Ln-s establish a soft connection to start

There are 7 levels of RunLevel in Linux (available in the/etc/inittab file settings), each of which corresponds to/ETC/RC.D/RC[0~6].D 7 directories:

TIPS:/ETC/RC[0~6].D is actually/ETC/RC.D/RC[0~6].D's soft connection, mainly to maintain compatibility with UNIX to do this strategy.

In these 7 directories, each directory holds the service that needs to be shut down or started when the corresponding RunLevel is loaded, as detailed information can be known, in fact, each script file corresponds to the specific service in the/etc/init.d/directory.

A script file that starts with K represents a run-level load that needs to be closed, and an S-beginning representative needs to execute:

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

[Email protected] ~]# 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, and the S start represents the load-time self-initiated.

If you need to set up self-booting at multiple runlevel, you need to establish multiple soft links, which is cumbersome and suitable for custom service scripting.

If some of the services already exist in the system (such as the HTTPD service item when you install Apache), you can use the following two methods:

The second way: Chkconfig

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

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

Above we turn off all the start levels of the SSHD service and then use the--level option to start the custom level;

The Tips:--list option allows you to view the startup status of a specified service, chkconfig all service statuses without any options.

The third Way: ntsysv pseudo-graphic

Ntsysv and Chkconfig are actually the same, but with a graphic only;

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

By default, what is the current runlevel, and what is the level of startup service set in Ntsysv, for example, my current runlevel is 3, then when I choose to start a service in the pseudo-graphical interface, it will run at a level of 3.

If you want to customize the RunLevel, you can use the Ntsysv--level method:

The above three operations need to ensure that the service script file executable, and to have root permissions, where the first method is more used for custom scripts, the second to third more for the system already exist services, such as FTP, samba, ssh, httpd, etc., 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 the service name start.

You can actually do this, service name start:

How do I set up service self-booting in Linux?

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.