What is init daemon in linux

init(8) — Linux man page

init is the parent of all processes on the system, it is executed by the kernel and is responsible for starting all other processes; it is the parent of all processes whose natural parents have died and it is responsible for reaping those when they die.

Processes managed by init are known as jobs and are defined by files in the /etc/init directory. See init(5) for more details on configuring Upstart.

Events

init(8) is an event-based init daemon. This means that jobs will be automatically started and stopped by changes that occur to the system state, including as a result of jobs starting and stopping.

This is different to dependency-based init daemons which start a specified set of goal jobs, and resolve the order in which they should be started and other jobs required by iterating their dependencies.

For more information on starting and stopping jobs, as well as emitting events that will automatically start and stop jobs, see the manual page for the initctl(8) tool.

The primary event is the startup(7) event, emitted when the daemon has finished loading its configuration. Other useful events are the starting(7), started(7), stopping(7) and stopped(7) events emitted as jobs change state.

System V compatibility

The Upstart init(8) daemon does not keep track of runlevels itself, instead they are implemented entirely by its userspace tools. The event emitted to signify a change of runlevel is the runlevel(7) event. For more information see its manual page.

Options

Options are passed to init(8) by placing them on the kernel command-line. —verbose Outputs verbose messages about job state changes and event emissions to the system console or log, useful for debugging boot.

Notes

init is not normally executed by a user process, and expects to have a process id of 1. If this is not the case, it will actually execute telinit(8) and pass all arguments to that. See that manual page for further details.

Files

Author

Reporting Bugs

Copyright © 2010 Canonical Ltd.
This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Читайте также:  Локальный сервер php linux

Источник

Init vs Systemd: What is an init daemon?

As a developer, I mostly work on Linux/Unix-like operating systems such as Ubuntu. Having used such operating systems for a few years now, I feel comfortable enough to say that I am familiar with them, but there are still many things that I still don’t understand. In this article, I would like to explore the difference between Init and Systemd. I remember during my System Administrator Devops internship, I had to perform some operations on some background service. At this point, I still had no idea what services were. I had to use commands like:

But why are there two commands that do exactly the same thing? Sadly, this question never crossed my mind. I was happy as long as the commands worked. That is, until I started working on Fedora CoreOS for Kubernetes and this happened:

$ sudo service kubelet sudo: service: command not found 

service is not a command?! After looking for an answer on Google, I found that the command was specific to certain Linux distributions and the solution was to use:

What!? A third command to manage services? Yup. In fact, some Linux distributions (distros) have their own command to manage services but I’m not going to go into that. In this article, I will only to talk about the init daemons Init and Systemd that use the commands service and systemctl respectively. But first, we need to understand what an init daemon is.

What is an Init Daemon?

The init daemon is the first process executed by the Linux Kernel and its process ID (PID) is always 1. Its purpose is to initialize, manage and track system services and daemons. In other words, the init daemon is the parent of all processes on the system.

What is Init?

Init (also known as System V init, or SysVinit) is an init daemon, created in the 1980s, that defines six run-levels (system states) and maps all system services to these run-levels. This allows all services (defined as scripts) to be started in a pre-defined sequence. The next script is executed only if the current script in the sequence is executed or timed out if it gets stucked. In addition to unexpected wait during execution timeouts, starting services serially makes the system initialization process inefficient and relatively slow. To create a service, you will need to write a script and store it in /etc/init.d directory. You would write a service script /etc/init.d/myService that looks something like this:

#!/bin/bash # chkconfig: 2345 20 80 # description: Description comes here. # Source function library. . /etc/init.d/functions start() < # TODO: code to start app comes here >stop() < # TODO: code to stop app comes here >case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) # TODO: code to check status of app comes here ;; *) echo "Usage: $0 " esac exit 0 

You can read about chkconfig in the man page. Essentially, it defines in which run-level your service should be run. Once you have your script, you can use the service command to start, stop, and restart your service.

What is Systemd?

Systemd (system daemon) is an init daemon used by modern systems and starts system services in parallel which remove unnecessary delays and speeds up the initialization process. What do I mean by parallel? Systemd uses Unit Dependencies to define whether a service wants/requires other services to run successfully, and Unit Order to define whether a service needs other services to be started before/after it. To create a service, you will need to write a .service file stored in the /etc/systemd/system directory. You would write a file /etc/systemd/system/myService.service that looks something like this:

[Unit] Description=Some Description Requires=syslog.target After=syslog.target [Service] ExecStart=/usr/sbin/ ExecStop=/usr/sbin/ [Install] WantedBy=multi-user.target 

I will discuss more about how to create a service with Systemd in another article. Once you have your service file, you can start, stop and restart your service using the systemctl command.

Conclusion

Init and Systemd are both init daemons but it is better to use the latter since it is commonly used in recent Linux Distros. Init uses service whereas Systemd uses systemctl to manage Linux services. 🐢

References

  • Creating a Linux service with systemd
  • How to Use Systemctl to manage Systemd Services and Units
  • The Story Behind ‘init’ and ‘systemd’
  • Understanding and Using Systemd
  • Init vs systemd
  • Differences between SysVinit, Upstart and Systemd

Источник

What is ‘init’ Process and Command in Linux?

In this article, you will learn about the short description of the init process, the runlevels of init, and the init command in a Linux system.

What is Init Process?

In layman’s terms, when you press the power button, your system will first look for the bootloader (basically, your Linux grub), and then it will try to launch the kernel.

But the kernel itself cannot launch all of the processes, so it will start the first (or parent) process, known as init (sort for “initialization“), with PID “1” (process identifiers are assigned in sequential order).

init process

The “/etc/inittab” script is used by the “init” process. It has entries for processes that do basic things when the system starts up and shuts down, like showing the user a login screen with gettys, mounting and unmounting file systems, and managing daemons.

As a result, it should be kept running until the system terminates. If the kernel is unable to start it, the system will reach a stage called “Kernel Panic“.

Run Levels

Run Levels is a system software configuration (by init) that defines a set of processes to start when the system boots. The processes spawned by the init for each of these run levels are defined in the file “/etc/inittab“.

Run Levels are numbered from zero to six and define the state of the machine after boot, as listed below.

Run Levels Mode Functions
0 Halt Halt the system.
1 Single-User Mode Get the system into single user mode.
2 Multi-User Mode Get the system into multiuser mode without networking.
3 Multi-User Mode with Networking Get the system into multiuser mode with networking.
4 Undefined Not used
5 X11 Get the system into multiuser mode with networking and X windows.
6 Reboot Reboot the system.

The majority of Linux systems is based on runlevel 3 or 5. Although, users can modify these runlevels or create new ones based on their requirements.

The 0, 1, and 6 are reserved runlevels used for halting, getting into single user mode, and rebooting the system.

Init Command in Linux

In most Linux systems, the init command is used to send control commands to the init daemons that run as background processes.

$ init [OPTION]

The following is a list of all known options, along with their descriptions.

Commands Description
0 Shutdown the system.
6 Reboot the system.
2, 3, 4, 5 Start runlevelX.target unit.
1, s, S Enter rescue mode.
q, Q Reload the init daemon configuration.
u, U Re-execute the init daemon.

Conclusion

There are numerous items that should be included, but the goal of this article is not to provide a detailed description of the init process or command; rather, it is to walk you through them.

If you are more interested in knowing the init process, then check this article, as this method of booting the system is deprecated with systemd, so there is no future plan to have a major update in this article.

If you are interested in learning about them from our site or want this article to be more concise, then do let me know in the comment section.

Источник

Оцените статью
Adblock
detector