OS: Manjaro 19.1 (certainly)
systemd is the first daemon process started on a Linux system (PID: 1). Starts other processes and becomes the ancestor process of all processes. It also has the purpose of managing other daemon processes (hence).
I mainly use the systemctl
command to inspect and manipulate systemd.
When you execute the systemctl
command, a list of units will pop up as shown below.
$ systemctl
UNIT LOAD ACTIVE SUB DESCRIPTION
sys-module-fuse.device loaded active plugged /sys/module/fuse
-.mount loaded active mounted Root Mount
boot-efi.mount loaded active mounted /boot/efi
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
[email protected] loaded failed failed User Manager for UID 1000
...
According to the man page, the systemctl
command (= systemctl list-units
command) "displays the list of units that systemd holds in memory".
What is a unit?
--Any resource that systemd knows how to operate and manage is called a unit. --Defined by a configuration file called unit file.
Well, in other words, it's an object unit managed by systemd.
For example, specify unit as shown below and check its status.
$ systemctl status bluetooth.service
The above bluetooth.service
is unit.
Once you get an overview.
The unit seems to be, for example, service (.service
), mount point (.mount
), device (.device
), socket (.socket
). (I don't understand in detail here.)
The full name of unit is required when using the systemctl command.
In other words, that is the bluetooth.service
.
However, there are rules that can use abbreviations. Three.
--If you omit the suffix, systemctl understands it as .service
. So bluetooth.service
can be written as bluetooth
.
--mount point is automatically interpreted as .mountʻunit.
/ home is equal to
home.mount. --device is also automatically interpreted as
.deviceʻunit. / dev / sda2
is equal to dev-sda2.device
.
Return to the previous command again. The output result is as follows.
$ systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
Loaded: loaded (/usr/lib/systemd/system/bluetooth.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2017-01-04 13:54:04 EST; 1 weeks 0 days ago
Docs: man:bluetoothd(8)
Main PID: 930 (bluetoothd)
Status: "Running"
Tasks: 1
Memory: 648.0K
CPU: 435ms
CGroup: /system.slice/bluetooth.service
└─930 /usr/lib/bluetooth/bluetoothd
Jan 12 10:46:45 example.com bluetoothd[8900]: Not enough free handles to register service
Jan 12 10:46:45 example.com bluetoothd[8900]: Current Time Service could not be registered
Jan 12 10:46:45 example.com bluetoothd[8900]: gatt-time-server: Input/output error (5)
The Loaded line shows loaded
if the unit is loaded in memory.
Other values are ʻerror,
not-found,
bad-setting,
masked`.
In addition, the path to the unit file and whether it is currently enabled (whether it boots at boot) are displayed in parentheses.
unit file
Here comes the unit file. From the previous output result, it seems that bluetooth.service is defined in /usr/lib/systemd/system/bluetooth.service. (When you actually look at the file, the contents are unexpectedly simple.)
As for the unit file, there seems to be a man page, so take a quick look. (systemd.unit (5)
)
It seems that there are various directives consisting of several sections.
These probably define unit.
Also, there was / usr / lib / systemd / system / *
in the place called System Unit Search Path.
It seems that the unit file of bluetoooth.service unit was searched from this directory.
Anyway, I found that a unit file with the same name as unit was placed in a specific directory, and unit was defined in that file.
Now that I've figured out how to manage systemd's units, let's take a look at specific commands.
systemctl status <unit>
The execution status, unit file path, pid, latest log, etc. are displayed.
systemctl start <unit>
Starts immediately.
systemctl stop <unit>
Stop immediately.
systemctl enabled <unit>
Set to enable. (Set to start at boot time.)
systemd looks at the unit file in a specific directory and manages the unit of operation, unit. These can be managed / manipulated by the user with the systemctl command.
Let's play by seeing what kind of unit is working and checking the state.
systemctl man page
Arch Linux wiki https://wiki.archlinux.org/index.php/Systemd#Using_units
Understanding Systemd Units and Unit Files https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files
Wikipedia https://en.wikipedia.org/wiki/Systemd
Recommended Posts