3

I have a systemd user service that works as expected. It is started like this:

systemctl start test@user

The problem is that I need to run this service on a timer possibly for multiple users. There doesn't seem to be a way to specify a user in the timer itself or a way to pass the username with the @ notation.

Here is the timer:

[Unit]
Description=Test (runs once every 24 hours)

[Timer]
OnUnitActiveSec=24h
Persistent=true
[email protected]

[Install]
WantedBy=timers.target

What confuses me is what to put in the "Unit=". If I put in "[email protected]" it works but then it will always run as a single user defeating the point of having a multi user service. Using "[email protected]" starts the timer but "systemctl status test@user" shows it as always inactive even with timer set to 1min interval.

I am not sure how to list the all running instances of a given systemd service so I don't know if "test@" service is running as a different user when a timer runs the service without the "@user".

What is the proper way to start user services with a timer? Ideally users should be able to create and manage their own services as well as timers that go along those services.

2 Answers 2

0

Does that answer what you need?

systemctl --user start unit.service
1
  • Adding some explanation why it would do so would be nice.
    – phk
    Commented Aug 9, 2018 at 9:13
0

Try to start the service inside the timer like this:

Unit=test@%u.service

From sytemd.unit(5) manpage for the specifier %u:

This is the name of the user running the service manager instance. In case of the system manager this resolves to "root". Note that this setting is not influenced by configurable in the of the service unit.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .