systemd
unit
-
Unit types
- automount
- device
- mount
- path
- scope
- service
- slice
- snapshot
- socket
- swap
- target
- timer
systemd - target
Get current targets
sc list-units --type=target# Output
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
bluetooth.target loaded active active Bluetooth Support
cryptsetup.target loaded active active Local Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface
integritysetup.target loaded active active Local Integrity Protected Volumes
local-fs-pre.target loaded active active Preparation for Local File Systems
local-fs.target loaded active active Local File Systems
multi-user.target loaded active active Multi-User System
network-online.target loaded active active Network is Online
network-pre.target loaded active active Preparation for Network
network.target loaded active active Network
nfs-client.target loaded active active NFS client services
nss-lookup.target loaded active active Host and Network Name Lookups
nss-user-lookup.target loaded active active User and Group Name Lookups
paths.target loaded active active Path Units
remote-fs-pre.target loaded active active Preparation for Remote File Systems
remote-fs.target loaded active active Remote File Systems
rpc_pipefs.target loaded active active rpc_pipefs.target
slices.target loaded active active Slice Units
sockets.target loaded active active Socket Units
sound.target loaded active active Sound Card
sshd-keygen.target loaded active active sshd-keygen.target
swap.target loaded active active Swaps
sysinit.target loaded active active System Initialization
timers.target loaded active active Timer Units
tpm2.target loaded active active Trusted Platform Module
veritysetup.target loaded active active Local Verity Protected Volumessystemd - service
[Service] - User
If you specify the user/group in the unit file then you should start the service as a system service.
If you want to start the service as a user service then the User/Group is not needed and can be removed from the unit config. You simply start the service when logged in as the current user passing the --user flag to systemctl.
systemd - service - oneshot
- Red Hat Blog - What sysadmins need to know about systemd's oneshot service type (opens in a new tab)
instantiated unit
unit generators
systemctl - cheatsheet
List active system units
scor
sc list-unitsor
sc-list-unitsList active user units
sc --useror
sc list-units --useror
sc-list-units --userList active sockets
sc list-socketsor
sc-list-socketsList active services
sc list-units --type serviceList all running units
sc --state runningDisplay unit status
sc status $unitor
sc-status $unitDisplay unit properties
sc show $unitor
sc-show $unitDisplay unit config
sc cat $unitor
sc-cat $unitCreate snippet to override a part of unit file
sc edit $unitor
sc-edit $unitReload changed unit files
sc daemon-reloador
sc-daemon-reloadReload changed configuration file
sc reload $unit ...Revert unit file changes by deleting overriding snippet file
sc revert $unitor
sc-revert $unitStart/Stop a service
sudo sc start/stop ${service_name}.serviceEnable/Disable a service from auto-start
sudo sc enable/disable ${service_name}.serviceStart system in text mode (Fedora)
sc set-default multi-user.targetStart system in graphical mode (Fedora)
sc set-default graphical.targetList the directories where systemd looks for unit files
systemd-analyze --user unit-pathsList the actual directories where systemd loaded unit files from
sc --user show -p UnitPath --value | tr ' ' '\n' | sortConfiguration files priority
/etc/run/usr/lib
Display an overview of overridden or modified unit files
systemd-delta --type=extendedCreate a SVG file showing when every service started, highlighting the time taken on initialization
systemd-analyze plot > $svg_file.svgsc - Prevent a service from running / Mask a service
sudo sc mask $service_namejournald
journalctl - cheatsheet
Display unit log
# Single unit
journalctl -u $unit
# Multiple units
journalctl -u $unit1 -u $unit2 ...Display logs from the current boot
journalctl -bList past boots
journalctl --list-bootsDisplay logs since yesterday
journalctl --since yesterdayDisplay logs of a specific process
journalctl _PID=$pidDisplay logs of the current user
journalctl _UID=$(id -u)Display kernel logs
journalctl -kDisplay logs in JSON format
# Compact
journalctl -o json
# Pretty print
journalctl -o json-prettyresolved
resolvectl - cheatsheet
DNS domain lookup
resolvectl query <domain>DNS IP reverse lookup
resolvectl query <IP>Show DNS configuration
resolvectl statusShow DNS servers
resolvectl dnsWSL
Resources
- systemd.unit — Unit configuration (opens in a new tab)
- DigitalOcean - How To Use Systemctl to Manage Systemd Services and Units | DigitalOcean (opens in a new tab)
- DigitalOcean - How To Use Journalctl to View and Manipulate Systemd Logs (opens in a new tab)
- How To Configure a Linux Service to Start Automatically After a Crash or Reboot – Part 1: Practical Examples | DigitalOcean (opens in a new tab)
- How To Configure a Linux Service to Start Automatically After a Crash or Reboot – Part 2: Reference | DigitalOcean (opens in a new tab)
- linode - systemctl Commands: Restart, Reload, Stop Service and More (opens in a new tab)