Systemd/User Services: Difference between revisions
Marked this version for translation Tags: Mobile edit Mobile web edit |
Added section clarifying linger settings and systemd's user management service |
||
| Line 32: | Line 32: | ||
By default, user services will be stopped when the user logs out and will start again when the user logs back in due to us setting {{ic|<nowiki>wantedBy = [ "default.target" ]</nowiki>}} in the example. | By default, user services will be stopped when the user logs out and will start again when the user logs back in due to us setting {{ic|<nowiki>wantedBy = [ "default.target" ]</nowiki>}} in the example. | ||
== | == Enabling the user management service and user process lingering == <!--T:7--> | ||
Without the user management unit {{ic|user@.service}}, commands such as {{ic|systemctl --user}} will fail, and configured options under {{ic|systemd.user}} will not take effect. This is typically observed on minimal systems without a desktop environment. | |||
When lingering is enabled for a user, the user management service is spawned at boot and can run services independently of the user's session, including keeping services running after a user logs out. | |||
<!--T:8--> | <!--T:8--> | ||
You can enable "[https://search.nixos.org/options?channel=unstable&show=users.users.%3Cname%3E.linger&from=0&size=50&sort=relevance&type=packages&query=users.users.%3Cname%3E.linger lingering]" by setting {{ic|<nowiki>users.users.<username>.linger = true;</nowiki>}} or running {{ic|sudo loginctl enable-linger [USER...]}}. | |||
<!--T:9--> | <!--T:9--> | ||
For a user service to start at boot, change the service configuration to {{ic|<nowiki>wantedBy = [ "multi-user.target" ];</nowiki>}}. | |||
== Enabling a service for specific users == <!--T:10--> | == Enabling a service for specific users == <!--T:10--> | ||