Three methods for setting service self-start in Linux
Source: Internet
Author: User
Sometimes we need the Linux system to automatically load some scripts or system services when starting the system. this operation is mainly performed in three ways: ln-s at/etc/rc. d/rc *. create/etc/init in the d directory. d/soft link of the service (* represents 0 ~ 6. one of the seven running levels) run the chkonfig command line...
Sometimes we need the Linux system to automatically load some scripts or system services when starting the system. this operation is mainly performed in three ways: ln-s at/etc/rc. d/rc *. create/etc/init in the d directory. d/soft link of the service (* represents 0 ~ 6. one of the seven running levels) chkonfig command line running level setting ntsysv pseudo graphics running level setting www.2cto.com note: 1. these three methods are mainly used for redhat-based release 2. if you do not know what the running level is, 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 the 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 the compatibility with Unix to make the policy www.2cto.com in the seven directories, each directory stores the services that need to be closed or started when loading at the corresponding running level. you can see the details. In fact, each script file corresponds to/etc/init. the script file starting with service K in the d/directory 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 script at startup, 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 [root @ localhost ~] # Ln-s/etc/init. d/sshd/etc/rc. d/rc3.d/S100ssh here, sshd is the script file for the specific service, and S100ssh is its soft link. S indicates auto-start during loading. if you need to set auto-start under multiple running levels, you need to create multiple soft links. this method is cumbersome. it is 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 is chkconfig. if you want to start some services by yourself, 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 it, you can add the -- level option. we will first disable all the startup levels of the sshd service, and then use the -- level option to start the custom level Tips: the -- list option can be used to view the startup status of a specified service. if chkconfig does not include any options, it can be used to view all service statuses. The third method is: ntsysv pseudo-graphics ntsysv and chkconfig are actually the same, there are two ways to start ntsysv by adding a graph. one is to directly input ntsysv in the command line, and the other is to use the setup command, and then select the system service by default, the current running level and the startup service level set in ntsysv. for example, if my current running level is 3, after I select start service in the pseudo graphic interface, the running level is also 3. if you want to customize the running level, you can use the ntsysv -- level method to perform the preceding three operations. you 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 set the running level, you need to find out the problem www.2cto.com Tips: to manually start a service, the traditional method is/etc/init. d. the service name start can also be like this. the service name start
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