Differences between SysVinit, Upstart and Systemd
Differences between SysVinit, Upstart and Systemd
https://www.computernetworkingnotes.com/linux-tutorials/differences-between-sysvinit-upstart-and-systemd.html#:~:text=To%20refer%20to%20the%20initialization%20process%2C%20the%20SysVinit,%27UNIX%20System%20V%27%20systems%20in%20the%20early%201980s.
systemd 服务和管理机制, 在系统启动和运行时都可以加载服务。
What is the systemd?
The systemd (system daemon) is a service and management mechanism. In RHEL7 or above, it is responsible for initializing and activating system resources and server daemons at the boot time as well as on a running system.
In easy language, the systemd starts and manages all types of processes and services in Linux. In technical language, it is an initializer program that brings the system up to a defined state by activating all services and processes those are enabled in that state. To know which services and processes are enabled in which state, it uses configuration files.
systemd是sysvinit和upstart初始化程序替代者。
内核对应进程0,
进程0启动进程1,进程对应systemd
SysVinit v/s Upstart v/s Systemd
Systemd is the replacement of the SysVinit and Upstart initializer programs. In RHEL6, the Upstart initialization program was used. Before RHEL6, the SysVinit was the default initialization program.
In order to understand the differences between SysVinit, Upstart, and Systemd, we have to understand the initialization process.
The kernel starts the initialization process immediately after the booting process. Since the Linux kernel uses process ID 0 to refer to itself, it assigns the process ID 1 to the initialization process.
Once started, the initialization process takes control of bringing the system up. It reads the configuration file and based on the configured state in the configuration file it starts all other services and processes. In easy language, you can say that the initialization process is the mother of all processes.
To refer to the initialization process, the SysVinit and Upstart use the term init while the systemd uses the term systemd. SysVinit, Upstart, and Systemd handle the initialization process differently.
sysvinit
最老,缺点是不支持热加载服务。
SysVinit
This initialization process was created for 'UNIX System V' systems in the early 1980s. After a little bit of customization, it was adopted in Linux. This classic initialization program worked well for many years. Till RHEL5, RedHat used this program as the default initialization program.
This process defines six system states known as run-levels and maps all processes and services with these run-levels. It also offers easy to use commands and methods for managing run-levels and their related services.
This program was created to work within a static environment. It does not work well with hot-plug devices. For example, suppose you have a Linux system that is using this program for services and processes management. If this system is in running state and you attach a USB device to the system, this program does not recognize that USB device.
This program starts all services in a pre-defined sequence. It executes the next script in the sequence only if the current script in the sequence is executed or timed out. If a script stuck during the execution, it had to wait until that script timed out. This unexpected wait makes the entire system initialization process less efficient and ultimately slower.
sysvinit的改进版本, 支持热加载,异步启动,自动重启
Upstart
The Upstart was created as a replacement for the SysVinit model. Unlike SysVinit which had created to operate in a static environment, the Upstart was created to operate in a flexible environment.
The Upstart provides three major benefits over the SysVinit. These benefits are; event-based service management, asynchronous services startup, and automatic restart of crashed services.
The Upstart, instead of using run-levels, uses system events to start and stop services. An event is a change in the system state. When an event occurs, the upstart detects that event and makes necessary changes.
An event can be anything that requires or triggers a change in the system state. The following are a few examples of events.
- A hot-plug device (such as USB drive) is plugged-in or removed from the system.
- The system boots up.
- A service is started or stopped.
The Upstart was developed as a replacement of SysVinit, not as a modern system initializer program. Upstart fully addressed all of SysVinit's shortcomings, but missed out on new features. Until a modern initializer program has been developed, to overcome the limitations of SysVinit, the Upstart was used as a temporary solution by many Linux developers. RedHat also used the Upstart in RHEL6.
现代版的系统初始化程序,
Systemd
The Systemd is the modern system initializer program. Most Linux developers including RedHat (from version 7) and Ubuntu (from version 15.04) use systemd as the default system initializer program.
Unlike its predecessors, the systemd is not easy to understand. To meet with modern system requirements, it contains several features and tools. These features and tools allow you to manage services, devices, sockets, mount points, swap area, unit types, targets, and many mores.
Advantages of the Systemd are the following.
- It starts services in parallel mode.
- It automatically resolves dependencies.
- It can repawn processes.
- It can track and relate processes together by using Linux control groups.
- It has been created to operate in the flexible modern environment. It means, it supports all types of modern hardware such as hot-plug devices and large data storages.
- It can start daemons on-demand without restarting the running service.
- It can create span-shot of the running system state.
- It can log events.
To provide above listed functions and many others, the systemd uses complex mechanism. In the next parts of this article, I will explain how the systemd works and how can you manage system through the systemd effectively.
That’s all for this tutorial. If you like this tutorial, please don’t forget to share it with friends through your favorite social platform.
sysvinit and systemd command
https://www.2daygeek.com/sysvinit-vs-systemd-cheatsheet-systemctl-command-usage/
Service Commands:
These are the most commonly used service commands on a Linux system to manage services.
Short Description SysVinit Command systemd Command To Start a Service service example start systemctl start example To Stop a Service service example stop systemctl stop example Stop and then Start a Service (Restart a Service) service example restart systemctl restart example Reload a Service (Reload the config file) service example reload systemctl reload example Restarts if the service is already running service example condrestart systemctl condrestart example How to check if a service is currently running service example status systemctl status example How to enable a service on boot/startup chkconfig example on systemctl enable example How to disable a service on boot/startup chkconfig example off systemctl disable example How to check if a service is configured to start on boot or not chkconfig example –list systemctl is-enabled example How to display a list of enabled or disabled services on boot with runlevels information chkconfig systemctl list-unit-files –type=service Create a new service file or modify any configuration chkconfig example –add systemctl daemon-reload
How to find out if a system uses SysV, Upstart or Systemd initsystem
The init process is always assigned PID 1. The
/proc
filesystem provides a way to obtain the path to an executable given a PID.In other words:
nathan@nathan-desktop:~$ sudo stat /proc/1/exe File: '/proc/1/exe' -> '/sbin/upstart'
As you can see, the init process on my Ubuntu 14.10 box is Upstart. Ubuntu 15.04 uses systemd, so running that command instead yields:
nathan@nathan-gnome:~$ sudo stat /proc/1/exe File: '/proc/1/exe' -> '/lib/systemd/systemd'
If the system you’re on gives
/sbin/init
as a result, then you’ll want to try statting that file:nathan@nathan-gnome:~$ sudo stat /proc/1/exe File: '/proc/1/exe' -> '/sbin/init' nathan@nathan-gnome:~$ stat /sbin/init File: ‘/sbin/init’ -> ‘/lib/systemd/systemd’
You can also execute it to find out more:
[user@centos ~]$ /sbin/init --version init (upstart 0.6.5) Copyright (C) 2010 Canonical Ltd.