How to Set service auto-start in Linux

Source: Internet
Author: User


Sometimes we need the Linux system to automatically load some scripts or system services when it is started, mainly in three ways: ln-s in/etc/rc. d/rc *. create/etc/init in the d directory. d/soft link of the service (* represents 0 ~ Note: www.2cto.com these three methods are mainly used for redhat-based release versions. If you do not know the running level, you 'd better first look at the relevant information before trying the first method: ln-s has 7 running levels in Linux (which can be set in the/etc/inittab file). Each running level corresponds to/etc/rc. d/rc [0 ~ 6]. d these seven directories: Tips:/etc/rc [0 ~ 6]. d is actually/etc/rc. d/rc [0 ~ 6]. d's soft connection is mainly used to maintain compatibility with Unix. In these seven directories, each directory stores the services that need to be closed or started when the corresponding running level is loaded. For details, see, in fact, each script file corresponds to/etc/init. d/specific services under the directory. The script file starting with www.2cto.com K indicates that the file needs to be closed during running-level loading, and the file starting with "S" indicates that the file needs to be executed. Therefore, when we need to start our own script, you only need to drop the executable script in/etc/init. d directory, and then in/etc/rc. d/rc *. d To create a soft link: www.2cto.com [root @ localhost ~] # Ln-s/etc/init. d/sshd/etc/rc. d/rc3.d/S100ssh here, sshd is the script file of the specific service, and it is its soft link. The start of "S" indicates that it is automatically started during loading. If you need to set auto-start under multiple running levels, you need to create multiple soft links. This method is cumbersome and applicable to custom service scripts. If some services already exist in the system (for example, httpd service items will exist when apache is installed), you can use the following two methods: the second method: chkconfig if you need to start some services, you only need to use the chkconfig service name on. If you want to disable it, change on to off. By default, chkconfig will automatically start the four levels of 2345. If you want to customize them, add the -- level option: We will first disable all the startup levels of the sshd service, then, use the -- level option to start the custom level. The Tips: -- list option can be used to view the startup status of the specified service. If chkconfig does not have any options, view the status of all services. Method 3: The ntsysv pseudo graph www.2cto.com ntsysv and chkconfig are actually the same, but only the graph is added. There are two ways to start ntsysv: one is to directly input ntsysv in the command line, the second is to use the setup command and then select the System Service: by default, the current running level is, And the startup service level set in ntsysv is, for example, my current running level is 3, so after I select to start the service in the pseudo graphic interface, its running level will also be 3. If you want to customize the running level, you can use the ntsysv -- level method: the above three operations must ensure that the service script file is executable and have the root permission, the first method is mostly used for custom scripts, and the second and third methods are mostly used for existing services in the system, such as ftp, samba, ssh, and httpd, to make relevant settings, you need to find out the running level issues. Www.2cto.com Tips: to manually start a service, the traditional method is/etc/init. d Service name start. The service name start:

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.