8

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
  • 207

1 Answers1

11

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.

u1686_grawity
  • 452,512