Ubuntu init and system service settings initInit is a program located in/sbin/init. it is in linux, during system startup, after all the device drivers and data structures are initialized, a user-level program started by the kernel and the init Program starts the system... ubuntu init and system service settings initInit is a program located in/sbin/init. it is in linux, during system startup, after all the device drivers and data structures are initialized, a user-level program started by the kernel and the init Program completes the system startup process. Www.2cto.com ubuntu is slightly different from traditional linux. upstart is used to start the system, but the init Program is still maintained on the surface. Traditionally, linux has several different running levels, including the following: #0-Downtime #1-single-user mode #2-multiple users, no NFS #3-full multi-user mode (standard running level) #4-reserved #5-X11 (x window) #6-after the system is restarted, the default level setting in the/etc/inittab file read by init determines the level at which the system is located. the system in half of the graphic interface enters Level 3. However, ubuntu is not the same as the traditional one. by default, the/etc/inittab file cannot be found, and the running level is also different. the specific levels are as follows: #0-shut down the system #1-single-user mode #2 ~ 5-full multi-user mode #6-restart that is to say, by default, levels 2, 3, 4, and 5 are the same, at the same time, the system's default level settings are not in the inittab file, but written in the/etc/init/rc-sysinit.conf file. Open this file and find the following sentence: env DEFAULT_RUNLEVEL = 2, which indicates that the system is currently in level 2 by default. In addition, there is a piece of code starting with if [-r/etc/inittab] in this article. the default running level function specified by the system using inittab is retained here, that is, if you have manually created/etc/inittab, init starts the system at the default running level specified in/etc/inittab. For example, if you want the system to use Level 3 as the default running level, you only need to add the following line in the inittab File: id: 3: initdefault: after determining the run level through/etc/init/rc-sysinit.conf, init will further run/etc/init. d/rc, and then enter/etc/rc [?] According to the level. D. start or close the corresponding service. Script for starting and disabling services in ubuntu stores the script for starting and disabling services and/etc/rc [?]. D directory. [X] indicates 0 ~ 6, corresponding to level 0 ~ 6. for example, rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d in the/etc directory. Assuming that the default level specified in the rc-sysinit.conf or inittab is 2, init will execute a script in the/etc/rc2.d directory to start or close the corresponding service. If/etc/rc [?] is enabled. D directory, you will find that all the files under these directories are symbolic links, such as Snnxxxx or Knnxxxx, and all point to/etc/init. d. That is to say, the startup or shutdown scripts of services at different running levels are put under/etc/init. d, but according to the needs of different levels, in the corresponding/etc/rc [?]. D. place a link to the directory. different levels require different services, so different/etc/rc [?]. The linked files in the d directory are also different. In the link file, the name starting with S indicates that/etc/init is called. the corresponding script in the d directory will pass a start parameter, that is, start the corresponding service, and start with K is to pass a stop parameter, thus disabling this service, K indicates kill. The nn after S and K is a number, indicating the order in which the script is executed. The trumpet is placed after the front and rear, so as to solve the possible successive dependencies between different services. For example, the ftp service depends on the start of the network service, so the ftp service number must be greater than the number of the network service, and then start the network service after it is started. The last xxxx at www.2cto.com is the service name. In addition, except for/etc/rc [0 ~ 6] In addition to the. d file, there is also a/etc/rc. d directory, in which the service script and/etc/rc [0 ~ 6] The. d format is similar. it is also a link to the script in/etc/init. d, but it will be in/etc/rc [0 ~ 6]. d is executed first before the script is executed. According to the above introduction, it is clear how to install a software as a service, that is, in/etc/init. d add a startup script for the service, and then at the corresponding level of/etc/rc to start the service [0 ~ 6] add a symbolic link to the script in/etc/init. d according to the file name format. Take apache2 as an example. by default, apache2 is compiled and installed in/usr/local/apache2, and the startup script of apache2 is/usr/local/apache2/bin/apachectl, to install the service, copy the apachectl to the/etc/rc [?] corresponding to the running level of the apache2 server to be started. In the d Directory, ubuntu runs under level 2 in half, so copy it to/etc/rc2.d. the command is as follows: sudo cp/usr/local/apache2/bin/apachectl/etc/init. d/httpd here, we change the copied script file name to the common httpd, then the name of apache2 in the system service is httpd. To manually add a service, you need to create a link in the form of Snnxxxx for httpd in/etc/rc2.d. Assume that the starting sequence is set to 80, and a point to/etc/init is created. d/httpd link/etc/rc2.d/S80httpd, command: sudo ln-s/etc/init. d/httpd/etc/rc2.d/S80httpd and then use sysv-rc-conf or chkconfig-list to check whether the httpd service has been created under runtime level 2, after the instance is restarted, apache2 is automatically started. To manually start, shut down, or restart the httpd server, you can use the service command + service name + parameter format. the following three commands are used to start, shut down, and restart the apache2 server: service httpd start service httpd stop service httpd restart to install the service in addition to the above manual links, you can also use some tool software for implementation, such as commonly used update-rc.d, chkconfig and sysv-rc-conf. Here the main update-rc.d as an example of update-rc.d such as update-rc.d in the runtime level 2, 3, 4, 5 are added to the httpd service startup command, and specify the startup number is 80, can be as follows (note that the last point number of the command cannot be less): sudo update-rc.d httpd start 80 2 3 4 5. if you want to add the httpd service close command in the running level 2, 3, and 4, and specify the close sequence number to 80, you can do the following (note that the last vertex number of the command cannot be less ): sudo update-rc.d httpd stop 80 2 3 4 5. if you want to delete the httpd service, use the following command to delete/etc/rc [?]. All existing points in d to/etc/init. d/httpd link: www.2cto.com sudo update-rc.d httpd remove In addition, you can also use the defaults parameter in the form of simultaneously to run Level 2, 3, 4, 5 to add the Startup Service Command, that is, the Start command, at the same time, add the close command to the running level 0, 1, and 6, that is, the Kill Command. the sequence number of the start command is 80, and the sequence number of the kill command is 90: sudo update-rc.d httpd defaults 80 90 this command is also equivalent to (note the command stop before and the last two dots cannot be less): sudo update-rc.d httpd start 80 2 3 4 5. stop 90 0 1 6. the effects of the above two commands are as follows:/etc/rc0.d/K90httpd-> .. /init. d/httpd/etc/rc1.d/K90httpd->.. /Init. d/httpd/etc/rc6.d/K90httpd-> .. /init. d/httpd/etc/rc2.d/S80httpd-> .. /init. d/httpd/etc/rc3.d/S80httpd-> .. /init. d/httpd/etc/rc4.d/S80httpd-> .. /init. d/httpd/etc/rc5.d/S80httpd-> .. /init. d/httpd chkconfig www.2cto.com: view the status of all services at all levels: chkconfig-list: chkconfig httpd is here. if httpd is started in 2, 3, 4, 5, the system will return the information: httpd 2345 sysv-rc-conf, which has a graphical interface and is relatively intuitive and simple, let's just talk about it. White. Www.2cto.com rc. local in/etc/rc [2 ~ 5] there will be a S99rc. local under the. d Directory. this is a link pointing to/etc/init. d/rc. local. you can see that in the normal 2 ~ The rc will be called at the end of the 5-level startup. local script, while/etc/init. d/rc. local will check whether/etc/rc exists. local, and run it. Therefore, we can go to/etc/rc. write code in local to start some programs with the system to implement functions similar to services. In summary, we can see that the system's startup call process is as follows: kernel →/etc/init/rc-sysinit.conf → [/etc/inittab] →/etc/init. d/rc →/etc/rc [?]. D →/etc/init. d/rc. local →/etc/rc. the structure and process of local files in other linux systems are slightly different from those in other systems. take CentOS5 in the Redhat system as an example. in the system, init uses the/etc/inittab file by default, then read/etc/rc. sysinit, and then enter/etc/rc [?] based on the running level. D. Among them,/etc/rc. sysinit is the link to/etc/rc. d/rc. sysinit,/etc/rc [?]. D is directed to/etc/rc. d/rc [?]. D link,/etc/rc. local is to/etc/rc. d/rc. so the system startup sequence is changed to kernel →/etc/inittab →/etc/rc. sysinit (/etc/rc. d/rc. sysinit) →/etc/rc [?]. D (/etc/rc. d/rc [?]. D) →/etc/rc. local (/etc/rc. d/rc. local)
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.