- What Is init.d and How To Use For Service Management In Linux
- init.d Location
- Init Daemon
- Daemon Script
- List Init.d Contents
- Init.d Script Usage
- What is init.d in Linux Service Management?
- What is init.d?
- How to Use init.d in Service Management?
- Как работают демоны, процесс Init и как у процессов рождаются потомки — изучаем основы Unix
- Как работают демоны, процесс Init и как у процессов рождаются потомки — изучаем основы Unix
- Как работает процесс Init
- Как работает разветвление процессов
- The Story Behind ‘init’ and ‘systemd’: Why ‘init’ Needed to be Replaced with ‘systemd’ in Linux
- What is init?
- What is systemd?
- Why there was a need to replace init?
- Systemd and Distro Integration
- systemd vs init
- Conclusion
- If You Appreciate What We Do Here On TecMint, You Should Consider:
What Is init.d and How To Use For Service Management In Linux
Linux operating systems generally uses boot loader like grub and lilo and than uses init process to start operating system and other services. init is the most important process which forks or creates other process in a Linux system. init.d is init configuration directory which holds information about the services or daemons.
init.d Location
init.d is located under /etc which is configuration directory for most of the Linux distributions. We can chech the existence of the init.d with the file command like below. It is a directory of course.
init.d Location
Init Daemon
init daemon is the first process of Linux system. Then other processes, services, daemons and threats are started by init . So init.d is a configuration database for init process.
Daemon Script
Now we will print an example daemon process. A daemon script will hold functions like start , stop , restart , status etc. We will use cron daemon script in this example.
Daemon Script
List Init.d Contents
There are a lot of different daemon and service scripts in init.d directory. We can list these scripts with the ls command like below.
List Init.d Contents
Init.d Script Usage
We can use these daemon scripts just by calling the like a regular bash script. Lets print some help information by calling script but not providing any option.
and then list the status of the cron daemon which is used for scheduled jobs.
Init.d Script Usage
Источник
What is init.d in Linux Service Management?
In Linux there are several services that can be started and stopped manually in the system, some of there services are ssh, HTTP, tor, apache, etc. To start and run these services we used to simply type
Example:
And to check if this service is running we type the command
In this simple manner, we are using service management in Linux but what actually happens and how it actually works in the background.
What is init.d?
All these service works on several scripts and these scripts are stored in /etc/init.d location, this init.d is daemon which is the first process of the Linux system. Then other processes, services, daemons, and threats are started by init. So init.d is a configuration database for the init process. Now let’s check some daemon scripts by printing some processes, a daemon script holds functions like start, stop, status and restart. Let’s check ssh as an example.
Output:
Now to you know about daemon script lets also check what is inside of init.d directory, to do this we will simply list out all the fines inside the location
Output:
How to Use init.d in Service Management?
We used to type simple command service ssh start. But now, in this case, we will do it the other way which is also simple.
Источник
Как работают демоны, процесс Init и как у процессов рождаются потомки — изучаем основы Unix
Как работают демоны, процесс Init и как у процессов рождаются потомки — изучаем основы Unix
Если вы когда-нибудь работали c Unix-системами, то наверняка слышали термин «демон». В этой статье я хочу объяснить, что это за демоны и как они работают, тем более что их название заставляет думать, что это что-то плохое.
Вообще демон — это фоновый процесс, который не привязан к терминалу, в котором был запущен. Но как они создаются, как они связаны с другими процессами, как они работают? Об этом мы и поговорим, но сперва давайте узнаем, как работает процесс init и как происходит рождение новых процессов.
Как работает процесс Init
Для начала поговорим о процессе init, также известном как PID 1 (поскольку его ID всегда равен 1). Это процесс создаётся сразу при запуске системы, то есть все другие процессы являются его потомками.
Обычно init запускается, когда ядро вызывает конкретный файл, обычно находящийся по адресу /etc/rc или /etc/inittab. Процесс устанавливает путь, проверяет файловую систему, инициализирует серийные порты, задаёт время и т.д. В последнюю очередь он запускает все необходимые фоновые процессы — в виде демонов. Все демоны обычно расположены в папке /etc/init.d/; принято оканчивать имена демонов на букву d (например, httpd, sshd, mysqld и т.п.), поэтому вы можете подумать, что директория названа так по этому же принципу, но на самом деле существует соглашение об именовании папок, содержащих конфигурационные файлы, именем с суффиксом .d. Итак, init запускает демонов, но мы так и не выяснили, как это происходит. Процесс init запускает демонов, создавая свои ответвления для запуска новых процессов.
Как работает разветвление процессов
Единственный способ создать новый процесс в Unix — скопировать существующий. Этот метод, известный как разветвление или форкинг, включает в себя создание копии процесса в виде потомка и системный вызов exec для запуска новой программы. Мы использовали слово «форкинг», поскольку fork — это реальный метод C в стандартной библиотеке Unix, который создаёт новые процессы именно таким образом. Процесс, вызывающий команду fork, считается родительским по отношению к созданному. Процесс-потомок почти полностью совпадает с родительским: отличаются лишь ID, родительские ID и некоторые другие моменты.
В современных дистрибутивах Unix и Linux процессы можно создавать и другим способами (например, при помощи posix_spawn), но большая часть процессов создаётся именно так.
Revolut , Moscow, можно удалённо , По итогам собеседования
Источник
The Story Behind ‘init’ and ‘systemd’: Why ‘init’ Needed to be Replaced with ‘systemd’ in Linux
I am subscribed to several mailing lists related to various Linux Distributions and Applications just to keep myself updated with what’s going on where. What are the new bugs? What are the Patches Released? What is expected in next release? and a whole lot of other stuffs. These days the mailing list is heavily populated with “Choose your side on Linux Divide”, mainly on Debian Mailing list along with a few other.
systemd replaces init
What “Choose your side on Linux Divide” is all about?
The init daemon is going to be replaced with daemon systemd on some of the Linux Distributions, while a lot of them have already implemented it. This is/will be creating a huge gap between traditional Unix/Linux Guard and New Linux Guard – programmers and System Admins.
In this article, we will discuss and solve following all queries one-by-one.
- What init is?
- What is systemd?
- Why init needed to be replaced?
- What features systemd will own.
What is init?
In Linux, init is a abbreviation for Initialization. The init is a daemon process which starts as soon as the computer starts and continue running till, it is shutdown. In-fact init is the first process that starts when a computer boots, making it the parent of all other running processes directly or indirectly and hence typically it is assigned “pid=1“.
If somehow init daemon could not start, no process will be started and the system will reach a stage called “Kernel Panic“. init is most commonly referred to as System V init. System V is the first commercial UNIX Operating System designed and usages of init on most of the Linux Distribution of today is identical with System V OS with a few exception like Slackware using BSD-style and Gentoo using custom init.
The need to replace init with something more perfect was felt from a long time and several alternatives were developed from time-to-time, some of which became distribution’s native init replacement, some of which are:
- Upstart – A init replacement daemon implemented in Ubuntu GNU/Linux and designed to start process asynchronously.
- Epoch – A init replacement daemon built around simplicity and service management, designed to start process single-threaded.
- Mudar – A init replacement daemon written in Python, implemented on Pardus GNU/Linux and designed to start process asynchronously.
- systemd – A init replacement daemon designed to start process in parallel, implemented in a number of standard distribution – Fedora, OpenSuSE, Arch, RHEL, CentOS, etc.
What is systemd?
A systemd is a System Management Daemon named with UNIX convention to add ‘d‘ at the end of daemon. So, that they can be easily recognized. Initially it was released under GNU General Public License, but now the releases are made under GNU Lesser General Public License. Similar to init, systemd is the parent of all other processes directly or indirectly and is the first process that starts at boot hence typically assigned a “pid=1“.
A systemd, may refer to all the packages, utilities and libraries around daemon. It was designed to overcome the shortcomings of init. It itself is a background processes which is designed to start processes in parallel, thus reducing the boot time and computational overhead. It has a lot other features as compared to init.
Why there was a need to replace init?
A init process starts serially i.e., one task starts only after the last task startup was successful and it was loaded in the memory. This often resulted into delayed and long booting time. However, systemd was not designed for speed but for getting the things done neatly which in turns avoid all the UN-necessary delay.
Features of systemd
- Clean, stateforward and efficient design.
- Simpler boot process.
- Concurrent and parallel processing at boot.
- Better API.
- Simple Unit Syntax.
- Ability to remove optional components.
- Low memory footprints.
- Improved technique to express dependencies.
- Initialization instruction written in config file and not in shell script.
- Make use of Unix Domain Socket.
- Job Scheduling using systemd Calendar Timers.
- Event Logging with journald.
- Choice of logging System events with systemd as well as syslog.
- Logs are stored in binary file.
- systemd state can be preserved to be called later in future.
- Track process using kernel’s cgroup and not PID.
- Users login managed by systemd-logind.
- Better integration with Gnome for interoperability.
Bottlenecks systemd
- Everything at one place.
- Not POSIX standard.
Systemd and Distro Integration
Linux Distribution | Integration |
Fedora | Yes, first distro to adopt systemd |
Arch | Yes |
RedHat | Yes |
CentOS | Yes |
Debian | Yes, Debian 8 codename Jessie will have systemd by default |
Gentoo | Yes, but needs to be downloaded, installed and configure side with custom init |
OpenSUSE | Yes |
Slack | No (Though it has not been adopted till now in slackware, Patric Volkerding has not shown any indication if it will be adopted or not) |
Ubuntu | Yes, needs to be installed and configured with Upstream. |
Controversy
Linus Torvalds, Chief architect of Linux kernel, feels attitude of key developer of systemd towards users and bug reports do not seems ok. It was also reported that systemd philosophy is weird and a foreign way to control system processes. The same has been recorded from Patric Volkerding and other notable Linux Users and Developers as well as over online forum, time-to-time.
systemd vs init
Features | init | systemd |
DBus Dependency – Mandatory | No | Yes |
Device based Activation | No | Yes |
Device dependency configuration with udev | No | Yes |
Timer based Activation | Cron/at | Proprietary |
Quota Management | No | Yes |
Automatic Service Dependency Handling | No | Yes |
Kills users Process at logout | No | Yes |
Swap Management | No | Yes |
SELinux integration | No | Yes |
Support for Encrypted HDD | No | Yes |
Static kernle module loading | No | Yes |
GUI | No | Yes |
List all the child processes | No | Yes |
Sysv compatible | Yes | Yes |
Interactive booting | No | Yes |
Portable to non x86 | Yes | No |
Adopted on | Several Distro | Several Distro |
Parallel service startup | No | Yes |
Resource limit per service | No | Yes |
Easy extensible startup script | Yes | No |
Separate Code and Configuration File | Yes | No |
Automatic dependency calculation | No | Yes |
Verbose debug | Yes | No |
Version | N/A | V44+ |
Size | 560 KB | N/A |
Number of Files | 75 files | 900 files + glib + DBus |
Lines of code – LOC | 15000 (Approx) | 224000 (Approx) (inc Codes, comments and white space) 125000 (Approx) (acctual code) |
Conclusion
Anything running as pid=1 must not break, must not be mess and must be controlled by users effectively and efficiently. Many-a-user believes that replacing init for systemd is nothing more than reinventing the wheel everytime as a side effect of Linux. But this is the diverse nature of Linux. This is because Linux is that much powerful. Change is good and we must appreciate it if it is for a good reason.
That’s all for now. I’ll be here again with another Interesting article you people will love to read. Till then stay tuned and connected to Tecmint. Don’t forget to provide us with your valuable feedback in the comments below.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник