pat
pat copied to clipboard
Improvement suggestion for systemd units: Provide user units alongside the system units
The systemd units provided by pat
are installed on the system level (and require sudo for administration). Have you considered using "user units" instead? Systemd runs a system service manager as root, but it also runs a user service manager for each active user (more on that below). For inspiration, Syncthing provide both system and user units (presumably for convenience).
The system and user unit files would be almost identical. The only difference is that:
- the user unit does not need any template parameter
- the user unit does not need the
User=%i
line -
WantedBy=default.target
is used instead ofmulti-user.target
- You used
sudo systemctl ...
for system units andsystemctl --user ...
for user units (no sudo) - The unit file is stored in
/usr/lib/systemd/user/pat.service
instead of/lib/systemd/system/[email protected]
If you have Syncthing installed, you can take a look yourself using systemctl cat syncthing@
and systemctl --user cat syncthing
.
One caveat is that the default behavior of systemd is to shut down the user service manager (and all its services) when the user logs out. It is also not started when the computer boots. This can be changed with configuration, however. Just run this command once:
sudo loginctl enable-linger $USER
When "linger" is active for the user, its service manager is tarted on boot and will remain running even if the user is logged out. This is great for servers.
What do you think? I can make the code changes and a pull request if thou think this is a good idea.