Ubuntuinit Startup Process Analysis

Source: Internet
Author: User
Currently, there are two mainstream init methods for Linuxdistros: one is the widely spread SystemVinitialization, which is derived from Unix and is still used by various Linuxdistros systems; the other is the Upstart method proposed in recent years. Based on the event mechanism, all services and tasks of the system are event-driven. As far as I know, Ubuntu (6.10 andlater), Fedora (9.10 andla

There are two mainstream init methods for Linux distros: one is the widely-Spread System V initialization, which is derived from Unix and is still used by various Linux distros; the other is the Upstart method proposed in recent years. Based on the event mechanism, all services and tasks of the system are event-driven. As far as I know, Ubuntu (6.10 and later), Fedora (9.10 and later), and Debian (optional) are the last methods ). Although there are not many releases using Upstart, it is designed to replace the old System V initialization.

As a knowledge organization, I will summarize the initialization processes of the two methods here. This is also to facilitate the organization of ideas:

In the past, I was always able to see the inittab when searching for information about the Linux system init process, but this file is not available on my Ubuntu, later, I realized that there was no inittab file on Ubuntu using Upstart. In the old-style System V initialization,/etc/inittab is a very important file. It is the first time the init process is started! Inittab initializes the system and sets the system runlevel and the commands to be executed for each runlevel. If the default runlevle set in inittab is 5, init runs/etc/init. d/rc 5 command, which executes the script/program in/etc/rc5.d Based on the dependency traversal of the system service. When you enter the/etc/rc5.d directory, you can find that all the files in the directory are soft links to the corresponding scripts/programs under/etc/init. d. Start with S, and stop with K. The two digits after S/K represent the service startup sequence (determined by the Service dependency ).

So what is Upstart job? We know that System V initializaiton is based on the init mode of inter-service dependency with runlevel as the core. However, in Upstart job, runlevel has an impact on service startup, but it is no longer the key. Upstart job is event-driven, and the startup and stop of system services are all determined by events. In turn, the startup and stop of system services can also be used as event sources to trigger other services. In addition, events are not necessarily generated within the system. You can manually type start/stop [Service] to generate an event to start/end the Service. Man upstart-evnets: Check the events defined by upstart job. runlevel is also treated as an event (events generated due to a change in runlevel), and other such events include startup, started, filesystem, and so on. Then how does the system service know when it should be started and when it should be terminated? The answer lies in/etc/init (some distros may be in/etc/event. d ). Go to the/etc/init directory and check whether the configuration files of the system service, or job definition files. (In fact, Upstart init only needs a directory such as/etc/init. Unlike System V init, it turns many circles to reach the destination, which is inferior to the former in terms of performance ). Open a file, such as cron. conf:

# cron - regular background program processing daemon
#
# cron is a standard UNIX program that runs user-specified programs at

# periodic scheduled times

description "regular background program processing daemon"

start on runlevel [2345]
stop on runlevel [!2345]

expect fork

respawn

exec cron

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.