Systemd/User Services: Difference between revisions

Unabomberlive (talk | contribs)
mNo edit summary
Pigs (talk | contribs)
Add usage section
 
(One intermediate revision by one other user not shown)
Line 47: Line 47:
You'll also likely want to change to {{ic|<nowiki>wantedBy = [ "multi-user.target" ];</nowiki>}} so the service starts at boot time.
You'll also likely want to change to {{ic|<nowiki>wantedBy = [ "multi-user.target" ];</nowiki>}} so the service starts at boot time.
</translate>
</translate>
== Enabling a service for specific users ==
By default, enabling a user service enables it for every user for which systemd spawns a service manager. If you wish for the service to be run only for specific users (say, {{ic|<nowiki>UserA</nowiki>}} and {{ic|<nowiki>UserB</nowiki>}}), use {{ic|<nowiki>ConditionUser</nowiki>}} ({{ic|<nowiki>man 5 systemd.unit</nowiki>}}):
<syntaxhighlight lang="nix">
systemd.user.services.my-cool-user-service = {
  unitConfig.ConditionUser = "UserA|UserB";
};
</syntaxhighlight>
Likewise, you can also disable a service for a specific user:
<syntaxhighlight lang="nix">
systemd.user.services.my-cool-user-service = {
  unitConfig.ConditionUser = "!root";
};
</syntaxhighlight>
== Usage ==
To interact with user-specific systemd services, use the <code>--user</code> flag with the <code>systemctl</code> command. For example, to check the status of a user service:
<syntaxhighlight lang="console"> $ systemctl --user status my-cool-user-service </syntaxhighlight>
To view logs for a specific user service, use <code>journalctl</code> with the <code>--user-unit</code> option:
<syntaxhighlight lang="console"> $ journalctl --user-unit my-cool-user-service </syntaxhighlight>
To list all active user units:
<syntaxhighlight lang="console"> $ systemctl --user list-units </syntaxhighlight>
[[Category:systemd]]
[[Category:systemd]]