6 User services
Anthony Wang edited this page 2024-07-07 00:26:59 +00:00

You can use systemd user services to manage daemons and other services.

Configuration

If you would like systemd to run your services even when you aren't logged in, run loginctl enable-linger.

Usage

Create a service file in the folder ~/.config/systemd/user with file extension .service. Use this template for the service file:

[Unit]
Description=

[Service]
ExecStart=

[Install]
WantedBy=default.target

Now to manage your user service, you can use the same systemctl commands you know and love, but with systemctl --user instead of just systemctl. Also, please make sure your service doesn't print a ridiculous amount of output to avoid spamming the system journal.

To make the service start at boot, make sure you have lingering enabled, and run systemctl --user enable SERVICENAME.

Tips and tricks

Automatically restart service

Add the following to the relevant sections of your service file. Make sure your service doesn't restart infinitely to avoid journal spam.

[Unit]
StartLimitInterval=200
StartLimitBurst=5

[Service]
Restart=always