Posts tagged with “systemd”

Running a systemd service as a regular user

A "note to self" post on how to create a systemd service and run it a regular user.

Assuming, you're logged in as a regular user, create the ~/.config/systemd/user/ directory using the mkdir -p ~/.config/systemd/user/ command. Then, create a .service file:

nano ~/.config/systemd/user/my_service.service

Specify the service options:

[Unit]
Description=My_service

[Service]
Restart=always
ExecStart=/path/to/executable
ExecStop=/usr/bin/kill -HUP $MAINPID

[Install]
WantedBy=default.target

It's important that WantedBy is set to default.target.

Save the unit file, and reload the systemd daemon using the systemctl --user daemon-reload command. Enable and start the service as the user:

systemctl --user enable my_service.service
systemctl --user start my_service.service

Finally, run the loginctl enable-linger $USER command.