Three ways to set up service self-booting in Linux

Source: Internet
Author: User

Sometimes we need the Linux system to automatically load some scripts or system services when booting up

This is done in three main ways:

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)

Chkonfig command line Run level settings

NTSYSV pseudo-graphic run level settings


Note: 1. These three methods are mainly used in Redhat-based distributions

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


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

There are 7 operating levels in Linux (available in the /etc/inittab file Settings), each running level corresponding to /ETC/RC.D/RC[0~6].D 7 Directories

650) this.width=650; "Src=" http://images.cnitblog.com/blog/476392/201301/ 18151041-096d449a91fa48f2bf12c4a50d6d2d74.png "style=" margin:0px;padding:0px;border:0px; "alt=" 18151041-096d449a91fa48f2bf12c4a50d6d2d7 "/>

Tips: /ETC/RC[0~6].D is actually a /etc/rc.d/rc[0~6].d soft connection, mainly to maintain compatibility with UNIX to do this strategy


In these 7 directories, each directory holds the services that need to be shut down or started when the corresponding RunLevel is loaded.

By the detailed information can be known, in fact, each script file corresponds to the /etc/init.d/ directory Specific Services

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

650) this.width=650; "Src=" http://images.cnitblog.com/blog/476392/201301/ 18151333-85c421f973864253b1e32f892fe8ec6f.png "style=" margin:0px;padding:0px;border:0px; "alt=" 18151333-85c421f973864253b1e32f892fe8ec6 "/>

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

LN -s/etc/init.d/sshd/etc/rc.d/rc3.d/s100ssh

Here sshd is a script file for a 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 under multiple runlevel, you need to set up multiple soft links

This approach is cumbersome and applies to custom service scripts

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

650) this.width=650; "Src=" http://images.cnitblog.com/blog/476392/201301/ 18152738-449524068e104327bc9e3e61d1049bdb.png "style=" margin:0px;padding:0px;border:0px; "alt=" 18152738-449524068E104327BC9E3E61D1049BD "/>

If you need to start some services, just use the chkconfig service name on, and if you want to turn it off, change it to off

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

650) this.width=650; "Src=" http://images.cnitblog.com/blog/476392/201301/ 18153144-0a443c680bad4964925caa140ce131e1.png "style=" margin:0px;padding:0px;border:0px; "alt=" 18153144-0a443c680bad4964925caa140ce131e "/>

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

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


The third Way: ntsysv pseudo-graphic

ntsysv and chkconfig are actually the same, but with a graphic.

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

650) this.width=650; "Src=" http://images.cnitblog.com/blog/476392/201301/ 18153614-7c42c0df7eec4c04b75578a21f83fc37.png "style=" margin:0px;padding:0px;border:0px; "alt=" 18153614-7c42c0df7eec4c04b75578a21f83fc3 "/>

By default, what is the current runlevel and what level of startup service is set in ntsysv

For example, my current operating level is 3, then I choose to start the service in the pseudo-graphical interface, it will run at the level of 3

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

650) this.width=650; "Src=" http://images.cnitblog.com/blog/476392/201301/ 18154058-87a724a3037c4870a48e66434caaa20f.png "style=" margin:0px;padding:0px;border:0px; "alt=" 18154058-87a724a3037c4870a48e66434caaa20 "/>


The above three operations need to ensure that the service script file executable, and to have root permissions

Among them, the first method is more used for custom scripts, and the second to third is more used for the services that exist in the system

such as FTP, samba, ssh, httpd, etc.

Also, to make the relevant settings need to figure out the operational level of the problem


Tips: If you want to start a service manually, the traditional way is /etc/init.d service name start

You can actually do this,service name start

650) this.width=650; "Src=" http://images.cnitblog.com/blog/476392/201301/ 18155018-03a4fcd414b543c2b06de3209d0866a2.png "style=" margin:0px;padding:0px;border:0px; "alt=" 18155018-03a4fcd414b543c2b06de3209d0866a "/>


This article is from the "Zolo CTO" blog, so be sure to keep this source http://zorro.blog.51cto.com/2139862/1410056

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.