Enable Systemd User-Service globally

3

1

Simple task. I have a user service that is installed globally on the system (i.e. in a path like /usr/lib/systemd/user). I now want to enable this service for all users on the system (i.e. make it enabled by default. I don't care whether users can disable it for themselves again or not). I do know I can enable the service as user via systemctl --user enable my.service - but that obviously only activates the service for the current user.

Not shure if relevant, but this is how the corresponding unit file looks. I tested it and it works:

[Unit]
Description=My App
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/myapp --systemd-log
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=default.target

Felix

Posted 2018-09-15T15:03:15.543

Reputation: 157

Answers

4

Use systemctl --global enable.

This will create a symlink in /etc/systemd/user/default.target.wants. Users will not be able to simply disable the unit, but they will still be able to edit (override) or completely mask it.

user1686

Posted 2018-09-15T15:03:15.543

Reputation: 283 655

I assume you meant enable not --enable, as that option does not seem to exist - but without the dashes it works as expected – Felix – 2018-09-15T18:14:02.010