systemd is a system and service manager
Management
Executing service management commands without understanding consequences will break installation.
-
Shows list of units
systemctl
📋 -
Shows status of specific unit
systemctl status UNIT_NAME
📋 -
Starts specific unit
sudo systemctl start UNIT_NAME
📋 Unit will not start on boot unless enabled; inspect status of services and timers via systemctl status. -
Restarts specific unit
sudo systemctl restart UNIT_NAME
📋 -
Stops specific unit
sudo systemctl stop UNIT_NAME
📋 -
Reloads specific unit (updates used configuration, if supported)
sudo systemctl reload UNIT_NAME
📋 -
Enables specific unit
sudo systemctl enable UNIT_NAME
📋 -
Disables specific unit
sudo systemctl disable UNIT_NAME
📋 -
Reloads systemd manager configuration
sudo systemctl daemon-reload
📋
systemd allows for user-level services (managed via --user
modifier). Note that user
services will only run when there's user session; session lingering is available via
sudo loginctl enable-linger
📋
although to
make systemctl --user to be available, following should be appended to .bashrc:
export XDG_RUNTIME_DIR="/run/user/$UID"
export DBUS_SESSION_BUS_ADDRESS="unix:path=${XDG_RUNTIME_DIR}/bus"
📋
Such services operate not from from
/etc/systemd/
📋
but from
/home/$USER/.config/systemd/user/
📋
Logs
-
Shows systemd logs
journalctl
📋 -
Shows logs of the systemd service/timer
journalctl -u UNIT_NAME.service
📋 -f switch allow to continue to follow logs of service/timer -
Shows logs of specific service for specific time period
journalctl -u UNIT_NAME.service -S 'since' -U 'until'
📋
Services
Instructions how to add custom systemd service
-
Create file
/etc/systemd/system/SERVICE_NAME.service
📋[Unit] After=network.target StartLimitIntervalSec=0 StartLimitBurst=5 Wants=SERVICE_NAME.timer [Service] Type=simple Restart=always RestartSec=1 User=USER Group=GROUP ExecStart=/bin/bash PATH_TO_EXECUTABLE [Install] WantedBy=multi-user.target
📋 -
Enable service and start it via
sudo systemctl enable --now SERVICE_NAME.service
📋
Timers
Instructions how to make custom systemd service run on specified schedule (modern alternative to CRON
scheduling)
External sources: https://wiki.archlinux.org/title/Systemd/Timers
-
Create file
/etc/systemd/system/SERVICE_NAME.timer
📋[Unit] Description=Run foo weekly Requires=SERVICE_NAME.service [Timer] Unit=SERVICE_NAME.service OnCalendar=weekly Persistent=true [Install] WantedBy=timers.target
📋OnCalendar - every minute is
*-*-* *:*:00
📋, usesystemd-analyze calendar "query"
📋 to check -
Enable and start timer via
sudo systemctl enable --now SERVICE_NAME.timer
📋This will run service out-of-schedule once, immediately.