On my journey to Linux, I have found that I needed to use sudo systemctl ... quite a lot to manipulate services and systems.
Here are my notes on my findings so far.
What is SystemD
SystemD is a software suite on Linux, it uses multiple system applications to manage services. It replaces older system and service management system like System V.
It aimed to harmonize the management between the existing linux distributions. To achieve this it provides replacements for various daemons and utiities such as device management, login management, network management, event logging…
ℹ️
Note
systemd comes from the Unix convnetions to name daemons by appending the letter ’d’. Of course there is also a double meaning as “System D” refers to the ability to adapt quickly to solve problems.
systemd is configured with plain-text files called unit-file using declarative language instead of bash scripts.
Commands
systemctl
status : gives information of a given process/service.
Ex: systemctl status docker
fha@TESTBOX:~/Repos/FhaNotes$ sudo systemctl enable docker
Synchronizing state of docker.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
disable
1
2
3
4
5
6
7
fha@TESTBOX:~/Repos/FhaNotes$ sudo systemctl disable docker
[sudo] password for fha:
Synchronizing state of docker.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install disable docker
Removed "/etc/systemd/system/multi-user.target.wants/docker.service".
Disabling 'docker.service', but its triggering units are still active:
docker.socket
reload
In some specific situation, this can be used to reload the configuration of a service without completely restarting it.
A usefull usecase is when configuration from a webserver must be updated, to prevent disconnecting users, the reload option can be used.
This works only if the service is actually implementing that functionality.
edit
This command edits the config file of a service.
There is 2 differentr way to use it.
The default creates a delta file with the changes of the file in a subdirectory.
The otehr way with –full will create a copy of the config file from the /lib/systemd/system folder to the /lib/systemd/system folder if it doesnt exists, and let you edit the full file as is.
1
sudo systemctl edit --full docker.service
daemon-reload
When updating service configuration, this allows to reload the sytemd service to take the new changes into consideration.
1
sudo systemctl daemon-reload
systemd-analyze
1
2
3
fha@TESTBOX:~/Repos/FhaNotes$ systemd-analyze
Startup finished in 45.965s (firmware) + 10.776s (loader) + 1.867s (kernel) + 14.834s (userspace)= 1min 13.444s
graphical.target reached after 14.789s in userspace.
Generate a pictures showing the bootup load sequence and time spent.
1
systemd-analyze plot > /tmp/bootup.svg
Service files (Unit-Files)
Extension : .service
The files can be in several folders in order of priority:
/etc/systemd/system :
/run/systemd/system : shows
/lib/systemd/system : When new packages are installed for services, the .service file will be created in this folder. Files created here can be overwritted when the package is updated.
3 sections
Unit : General information about the service.
Service : Defines how service is started, stopped or reloaded.
Install : -
Unit file Types
.service
.socket
.device (automatically initiated by systemd[67])
.mount
.automount
.swap
.target
.path
.timer (which can be used as a cron-like job scheduler[68])
.snapshot
.slice (used to group and manage processes and resources[69])
.scope (used to group worker processes, not intended to be configured via unit files[70])