
Much like a package management system, systemd defines a robust dependency model, not only among services but also among “targets,” systemd’s term for the operational modes that traditional init calls runlevels. systemd not only manages processes in parallel, but also manages network connections (networkd), kernel log entries (journald), and logins (logind).
UNIX and linux system administration handbook
An entity that is managed by systemd is know as a unit. The behaviour of a unit is specified in a unit file.
which encapsulate local IPC or network sockets in the system, useful for socket-based activation.
useful to group units, or provide well-known synchronization points during boot-up
mount points in thefile system
triggering activation of other units based on timers.
/usr/lib/systemd/etc/systemd$HOME/.config/systemd/user[Unit]
Description=fast remote file copy program daemon
ConditionPathExists=/etc/rsyncd.conf
[Service]
ExecStart=/usr/bin/rsync --daemon --no-detach
[Install]
WantedBy=multi-user.target
Wants, Requires, Requisite, Before, After
weak requirement dependencies on other units. , if the listed units fail to start this unit will still be started.
If one of the other units fails to activate, this unit will not be started. Besides, with or without
if the units listed here are not started already, they will not be started and the starting of this unit will fail immediately.
Those two settings configure ordering dependencies between units. When two units with an ordering dependency between them are shut down, the inverse of the start-up order is applied.
This defines services by their process and daemonizing behavior.
This directive set the path and arguments of the executable command for the unit.
This specifies an additional command that executes before ExecStart.
This configures the path to commands that will be executed after ExecStart.
the service manager will consider the unit started immediately after the main service process has been forked off
the service manager will consider the unit started immediately after the main service binary has been executed.
the service manager will consider the unit up after the main process exits
the service manager will consider the unit when a callback is performed
Units that is used to define markers and operating modes
single-user, multi-user, graphical, network-online
target correspond to run-level
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.target
Wants=sshd-keygen.target
[Service]
Type=notify
EnvironmentFile=-/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target[Unit]
Description=Cockpit Web Service
Documentation=man:cockpit-ws(8)
Requires=cockpit.socket
Requires=cockpit-wsinstance-http.socket cockpit-wsinstance-https-factory.socket
# ensure our DynamicUser exists
Requires=cockpit-ws-user.service
After=cockpit-ws-user.service
# we need to start after the sockets so that we can instantly forward incoming requests
After=cockpit-wsinstance-http.socket cockpit-wsinstance-https-factory.socket
[Service]
RuntimeDirectory=cockpit/tls
ExecStartPre=+/usr/libexec/cockpit-certificate-ensure --for-cockpit-tls
ExecStart=/usr/libexec/cockpit-tls
User=cockpit-ws
Group=cockpit-ws
...
[Install]
# Not present! Socket activated| command | action |
|---|---|
systemctl status | systemctl show system status |
| command | action |
|---|---|
systemctl start unit | Start a unit immediately |
systemctl stop unit | Stop a unit immediately |
systemctl enable unit | enable/install a unit immediately |
systemctl disable unit | disable/uninstall a unit immediately |
systemctl status unit | inspect a unit status |
systemctl restart unit | Restart a unit |
systemctl daemon-reload | Reload systemd manager configuration |
➜ ~ sudo systemctl status sshd
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; preset: enabled)
Drop-In: /usr/lib/systemd/system/service.d
└─10-timeout-abort.conf
Active: active (running) since Fri 2024-09-20 22:29:57 CEST; 1 week 4 days ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 1828 (sshd)
Tasks: 1 (limit: 47576)
Memory: 188.0K (peak: 3.9M swap: 1.2M swap peak: 1.2M)
CPU: 105ms
CGroup: /system.slice/sshd.service
└─1828 "sshd: /usr/sbin/sshd -D [listener] 0 of 10-100 startups"
Sep 20 22:29:57 Derinoe systemd[1]: Starting sshd.service - OpenSSH server daemon...
Sep 20 22:29:57 Derinoe (sshd)[1828]: sshd.service: Referenced but unset environment variable evaluates to an empty string: OPTIONS
Sep 20 22:29:57 Derinoe sshd[1828]: Server listening on 0.0.0.0 port 22.
Sep 20 22:29:57 Derinoe sshd[1828]: Server listening on :: port 22.
Sep 20 22:29:57 Derinoe systemd[1]: Started sshd.service - OpenSSH server daemon.
Sep 26 17:05:30 Derinoe sshd[565393]: Connection closed by 192.168.112.177 port 57411
➜ ~ journalctl -b -1
Sep 14 10:58:32 Derinoe kernel: Linux version 6.10.8-200.fc40.x86_64 (mockbuild@81267993c0ea4676bef76f8dd2b2ffea) (gcc (GCC) 14.2.1 202>
Sep 14 10:58:32 Derinoe kernel: Command line: BOOT_IMAGE=(hd0,gpt3)/vmlinuz-6.10.8-200.fc40.x86_64 root=UUID=fc98b53c-d69c-4ff7-9a46-e5>
Sep 14 10:58:32 Derinoe kernel: BIOS-provided physical RAM map:
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009efff] usable
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000000009f000-0x00000000000fffff] reserved
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x0000000000100000-0x000000004f23bfff] usable
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000004f23c000-0x000000004f23dfff] reserved
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000004f23e000-0x000000006b69efff] usable
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000006b69f000-0x000000006fa36fff] reserved
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000006fa37000-0x000000006fca9fff] ACPI NVS
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000006fcaa000-0x000000006fd0efff] ACPI data
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000006fd0f000-0x000000006fd0ffff] usable
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x000000006fd10000-0x0000000077ffffff] reserved
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x0000000078000000-0x00000000787fffff] usable
Sep 14 10:58:32 Derinoe kernel: BIOS-e820: [mem 0x0000000078800000-0x000000007f7fffff] reservedLogging last boot, all services
➜ ~ journalctl -u greetd.service
-- Boot 9feeb89f09e240fe90a151e5b49021a1 --
Jul 29 14:03:03 Derinoe systemd[1]: Started greetd.service - Greeter daemon.
Jul 29 14:03:03 Derinoe greetd[2160]: pam_unix(greetd-greeter:session): session opened for user greetd(uid=980) by (uid=0)
Jul 29 14:03:21 Derinoe greetd[2252]: pam_unix(greetd:auth): check pass; user unknown
Jul 29 14:03:21 Derinoe greetd[2252]: pam_unix(greetd:auth): authentication failure; logname= uid=0 euid=0 tty= ruser= rhost=
Jul 29 14:03:21 Derinoe greetd[2252]: gkr-pam: error looking up user information$ mkdir -p ~/.config/systemd/user
$ touch ~/.config/systemd/user/jupyter.service
[Unit]
Description=Jupyter
[Service]
Type=simple
ExecStart=/home/user00/jupyterlab/bin/jupyter-lab --port 8000
Restart=always
[Install]
WantedBy=default.target
$ systemctl daemon-reload --user
$ systemctl enable jupyter --user
$ systemctl start jupyter --user
# inspect log
$ journalctl -u jupyter --user
What happened in the "~/.config/systemd/user" folder?