Systemd manages Linux system resources through units. A unit can represent a service, target, mount point, timer, socket, or another system resource.
Unit files are usually stored in one of these directories, ordered by priority:
/etc/systemd/system: custom system or user configuration.
/run/systemd/system: runtime-generated configuration.
/usr/lib/systemd/system: unit files installed by the system or third-party software.
Systemd reads many default unit files from /usr/lib/systemd/system/, while /etc/systemd/system/ often contains custom files or symbolic links.
A Unit is the basic object managed by Systemd. A Target is a group of units, similar to a SysV-init runlevel.
Common service unit sections:
[Unit]: description and dependency metadata.
[Service]: service lifecycle and runtime behavior.
[Install]: how the unit is enabled and attached to a target.
Example service unit:
ExecStartPre=-/usr/bin/docker kill busybox1
ExecStartPre=-/usr/bin/docker rm busybox1
ExecStartPre=/usr/bin/docker pull busybox
ExecStart=/usr/bin/docker run --name busybox1 busybox /bin/sh -c
ExecStop="/usr/bin/docker stop busybox1"
ExecStopPost="/usr/bin/docker rm busybox1"
WantedBy=multi-user.target
systemctl list-units --all
systemctl list-units --failed
systemctl list-units --type=service
systemctl status bluetooth.service
sudo systemctl start apache.service
sudo systemctl stop apache.service
sudo systemctl restart apache.service
sudo systemctl daemon-reload
systemctl list-dependencies nginx.service
systemctl list-unit-files --type=target
systemctl list-dependencies multi-user.target
sudo systemctl set-default multi-user.target
sudo systemctl isolate multi-user.target
Systemd uses Journald for logs. Use journalctl to inspect system and service logs.
[1]. https://cloud.tencent.com/developer/article/1516125
[2]. https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/system_administrators_guide/chap-managing_services_with_systemd
[3]. Execute-Scripts-on-Period-with-Systemd
[4]. Manage-Podman-Container-With-Systemd