Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Last active October 9, 2024 15:17
Show Gist options
  • Save jdmichaud/0d945c3b7d4fa6c325b804c956281246 to your computer and use it in GitHub Desktop.
Save jdmichaud/0d945c3b7d4fa6c325b804c956281246 to your computer and use it in GitHub Desktop.
systemd cheatsheet

Create a systemd service

Create a unit file in /etc/systemd/system named foo.service. Then:

sudo systemctl start foo

If the file is modified:

sudo systemctl daemon-reload
sudo systemctl restart foo

Check the status

systemctl status foo

To list the status of a group of service in a compact form:

systemctl --user list-units foo\*.service

To watch that status live, with an update every second (-n 1):

watch -n 1 systemctl --user list-units foo\*.service

Remove a service

Stop the service, disable it (in case you enabled it), remove the unit file, reload the daemon and reset failed services:

systemctl stop foo
systemctl disable foo
rm /etc/systemd/system/foo.service
systemctl daemon-reload
systemctl reset-failed

Logging

Check the logs:

journalctl -u foo

Erase the logs:

Only the logs (no timestamp or other info)

journalctl --output cat -u foo.service

Start the service at boot

sudo systemctl enable foo

Group services

Use a target: https://www.freedesktop.org/software/systemd/man/latest/systemd.target.html To investigate: https://unix.stackexchange.com/a/516323

To use service at user level

https://sekor.eu.org/techlog/systemd-without-root-instances/

Create the unit files in ~/.config/systemd/user/.

Then use systemctl --user as you sytemctl command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment