I want to understand systemd roughly

environment

OS: Manjaro 19.1 (certainly)

systemd conceptual

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).

systemctl command

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?

What is 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.

Operate unit

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.

Specific command of systemctl

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.)

Summary

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.

reference

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

I want to understand systemd roughly
I want to manage systemd by time zone! !!
I want to solve Sudoku (Sudoku)
I want to understand (engineering) UMAP stronger than t-SNE
Even beginners want to say "I fully understand Python"
I want to fully understand the basics of Bokeh
I want to scrape images to learn
I want to do ○○ with Pandas
I want to copy yolo annotations
I want to debug with Python
I want to pin Spyder to the taskbar
I want to detect objects with OpenCV
I want to output to the console coolly
I want to print in a comprehension
I want to scrape them all together.
I want to handle the rhyme part1
I want to know how LINUX works!
I want to blog with Jupyter Notebook
I want to handle the rhyme part3
I want to use jar from python
I want to build a Python environment
I want to use Linux on mac
I want to pip install with PythonAnywhere
I want to analyze logs with Python
I want to play with aws with python
I want to use IPython Qt Console
I want to display the progress bar
I want to make an automation program!
I want to embed Matplotlib in PySimpleGUI
I want to handle the rhyme part2
I want to develop Android apps on Android
I want CAPTCHA to say HIWAI words
I want to handle the rhyme part5
I want to handle the rhyme part4
I want to make matplotlib a dark theme
I want to connect to PostgreSQL from various languages
I want to do Dunnett's test in Python
I want to have recursion come to my mind
I want to easily create a Noise Model
I want to use MATLAB feval with python
I want to analyze songs with Spotify API 2
I want to INSERT a DataFrame into MSSQL
I want to create a window in Python
Anyway, I want to check JSON data easily
I want to email from Gmail using Python.
[Python] I want to manage 7DaysToDie from Discord! 1/3
I want to perform SageMaker inference from PHP
I want to mock datetime.datetime.now () even with pytest!
I want to display multiple images with matplotlib.
I want to knock 100 data sciences with Colaboratory
I want to make a game with Python
I want to visualize csv files using Vega-Lite!
I want to handle the rhyme part7 (BOW)
I want to be an OREMO with setParam!
I don't want to take a coding test
I want to store DB information in list
I want to analyze songs with Spotify API 1
I want to merge nested dicts in Python
I want to make fits from my head
I want to use Temporary Directory with Python2
I want to get League of Legends data ③