Upstart: Ubuntu event-based startup process

Source: Internet
Author: User
Article Title: Upstart: an event-based startup process of Ubuntu. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

Translator: Wang Xu (gnawux at gmail.com)

Although the translator is a hardcore Debian fan, he has been paying attention to upstart for a long time. In the opinion of the translator himself, upstart is the most outstanding of all the work Ubuntu has done, it can greatly speed up the Linux system startup process. Although it is not the only next-generation init program, it has been used as the default init process of Ubuntu for a long time, which will greatly help program maturity; and, upstart uses an event-based model instead of simply parallelizing various daemon. This architectural breakthrough is revolutionary. Let's take a look at this article.

Because the traditional System V init daemon (Sysvinit) cannot handle modern hardware well, such as hot swapping devices, USB hard drives or mountain villages, and network file systems, Ubuntu uses Upstart init daemon.

This article is based on the recently published A Practical Guide to Ubuntu Linux.

There are already a variety of alternative products for sysvinit. The most famous one is initng, which can be used for Debian and can also work on Ubuntu. In the same location, Solaris uses SMF (Service Management Facility), while Mac OS uses launchd. Ubuntu is more inclined to combine the advantages of these software.

Sysvinit daemon is a runtime-LEVEL initialization program that uses the runtime level (such as single-user, multi-user, etc.) and ?. D directory to the/etc/init. d directory to start and end the system service. Since Feisty, Ubuntu has switched to Upstart init daemon and started to convert Sysvinit settings to Upstart settings. This article discusses the traces of Upstart and some remaining Sysvinit:/etc/rc ?. D and/etc/init. d directory and concept of running level.

Upstart init daemon is based on events. When conditions change in the system, it runs a specific program. Most of the programs run here are scripts used to start or stop the service. This configuration method is similar to the concept of running the init script when the system enters a certain running level, but upstart is more flexible. Upstart can not only start or stop the service when the operation level changes, but also start or terminate the service when other system changes are received. Changes to these systems are called "events ". For example, when upstart receives the file system loading, printer installation, or other similar device addition or deletion information from udev and takes corresponding actions. Upstart can also start or close services when the system starts, closes, or the status of a task changes.

Upstart is composed of five packages (in Ubuntu) which will be installed by default:

Upstart provides Upstart init daemon and initctl tools.

Upstart-logd provides the job definition files for logd daemon and logd services.

Upstart-compat-sysv provides the rc job definition file and reboot, runlevel, shutdown, telinit, and other tools for compatibility with sysvinit.

Startup-tasks provides a job definition file for system startup tasks.

System-services provides the working definition file of the tty service.

Definition

There are several terms that help us understand init-related things. Event is the status change information that init can obtain. Almost all internal or external State Changes of the system can trigger an event. For example, the boot program will trigger the startup event. When the system enters runtime Level 2, it will trigger the runlevel 2 event, file System loading triggers the path-mounted event, and unplug or install a hot swapping or USB device (such as a printer) also triggers a time. You can also use the initctl emit command to manually trigger an event.

A job is a series of commands that init can understand. Typical Commands include the name of a program (binary file or script) and an event. Upstart init daemon runs the corresponding program when the event is triggered. You can use the initctl start and stop commands to manually start or terminate a job. Jobs can be divided into tasks and services.

A task is a task that runs and returns to the waiting state after execution.

Services are jobs that do not end on their own. For example, logd daemon and gettys are implemented as services. Init daemon monitors the status of each service. If a service encounters a problem, the service will be restarted and the service will be killed when some events are triggered or manually stopped.

The/etc/event. d directory contains a series of work definition files (Files defining the work run by upstart init daemon ). Initially, this directory is generated by the Upstart package. In Ubuntu after Feisty, the installed Service will add a file for controlling the service to this directory. Which of the files will be installed in/etc/rc instead ?. D and/etc/init. d directory files.

The core of Upstart init daemon is a state machine. It keeps track of the status of each job. When an event is triggered, it tracks the status changes of the job. When init traces the status of a job from one to another, it may execute the job command or terminate the job.

System V's init daemon starts or stops services by changing the running level. The Ubuntu system that uses Upstart init daemon does not have a running level concept. To smoothly port a running-level system to an event-based system and provide compatibility for software of other releases, Ubuntu uses Upstart to simulate the running level.

In/etc/event. d/rc? What is the rc defined in the file? The job will run the/etc/init. d/rc Script, which will run the link to/etc/rc ?. Run the startup script in/etc/init. d In the d directory to simulate SysVinit. When the system enters a running level, rc? The scripts will be run at work. At the same time, Upstart provides runlevel and telinit tools to provide compatibility with SysVinit.

With initctl (init control), administrators with root permissions can communicate with Upstart init daemon. This tool can be used to start, stop, or report a job. For example, the initctl list command lists all jobs and their statuses:

$ Sudo initctl list logd (stop) waitingrc-default (stop) waitingrc0 (stop) waiting... Tty5 (start) running, process 4720tty6 (start) running, process 4727

For more details, refer to the man page of initctl or the example in this section. You can use the initctl help command (there is no horizontal bar before help) to list the commands of initctl. In addition, you can also use initctl list? Help to list the help information of the list command, of course, transfer the list to other initctl commands will get the corresponding information of this command. The start, stop, and status tools are links to initctl, and the corresponding commands of initctl are directly run.

[1] [2] [3] Next page

Related Article

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.