For system units, managed by the root user, use the directory /etc/systemd/system
.
For user managed units use the directory ~/.config/systemd/user
.
Units that come from installed packages normally use the directory /usr/lib/systemd/system
.
To override existing preconfigured units use the command systemctl edit <unit>
or add the file /etc/systemd/system/<unit>/override.conf
with the changed options.
To run the service manager (systemctl
) in user-mode for user managed units in the ~/.config/systemd/user
directory, add the --user
parameter to every execution like this:
systemctl status --user <unit>
After adding or changing a unit file reload the changes with:
systemctl daemon-reload
Start a unit:
systemctl start <unit>
Stop a unit:
systemctl stop <unit>
Restart a unit:
systemctl restart <unit>
Asks a unit listed on the command line to reload it's configuration (for the example case of Apache, this will reload Apache's httpd.conf in the web server, not the apache.service systemd unit file):
systemctl reload <unit>
Enable a unit (add to autostart):
systemctl enable <unit>
Install a unit (create symlinks from [Install]
section for auto start) and start it afterwards:
systemctl enable --now <unit>
Disable a unit (remove symlinks made with enable
) and stop it afterwards:
systemctl disable --now <unit>
Display status of a unit:
systemctl restart <unit>
Mask a unit to make it impossible to start:
systemctl mask <unit>
Unmask a unit:
systemctl unmask <unit>
Undo all changes made to a unit file with edit
or mask
:
systemctl revert <unit>
List all timers:
systemctl list-timers [--all]
System units:
journalctl --unit <unit>
User units:
journalctl --user-unit <unit>
Syntax check of unit file:
systemd-analyze verify [--user] <unit>
Escape strings for usage in systemd mount unit names:
systemd-escape mnt/example
Calculate the next 10 elapses of a calendar expression for a timer:
systemd-analyze calendar --iterations=10 <expression>
-
Create the unit file
- Either with
systemctl
systemctl edit --user --force --full example.service
- or by creating the unit file manually and then reloading the daemon
systemctl daemon-reload --user
- Either with
-
Install the service and start it
systemctl enable --user --now example.service
-
Check the status to see if the service is running
systemctl status --user example.service
-
Remove all drop in files
systemctl revert --user example.service
-
Uninstall the service and stop it
systemctl disable --user --now example.service
-
Delete the unit file
rm "$(systemctl show --user -P FragmentPath test.service)"
-
Reload the daemon
systemctl daemon-reload --user
-
Reset a possible "failed" state
systemctl reset-failed --user example.service
systemd.unit
systemd.mount
systemd.automount
systemd.path
systemd.service
systemd.timer