I have a couple of services (static site generators) that I want to trigger on a regular basis from the same systemd timer. I found this question/answer, which covers exactly what I want to do, and describes a setup whereby a .target
file that Wants=
multiple services is triggered by a corresponding timer. This sounds great, but I'm finding that when I actually set this up, it only ever triggers once, then disables itself!
I've prepared a minimal working example (this doesn't trigger multiple services, but demonstrates the same problem):
test-timer.timer
:
[Unit]
Description=A test timer
[Timer]
OnCalendar=*-*-* *:*:30
Unit=test-timer.target
[Install]
WantedBy=timers.target
test-timer.target
:
[Unit]
Description=Target unit
Wants=test-timer.service
After=test-timer.service
[Install]
WantedBy=timers.target
test-timer.service
:
[Unit]
Description=Run test
[Service]
ExecStart=/usr/bin/bash -c "date --rfc-3339='seconds' >> /tmp/test-timer-output"
[Install]
Also=test-timer.target
Enable the timer:
$ sudo cp test-timer.* /etc/systemd/system/
$ sudo systemctl enable --now test-timer.timer
Created symlink /etc/systemd/system/timers.target.wants/test-timer.timer → /etc/systemd/system/test-timer.timer.
Then, when I look at the output of systemctl list-timers --all
, prior to the first run I get (ignoring other timers):
NEXT LEFT LAST PASSED UNIT ACTIVATES
Fri 2021-10-08 10:38:30 EDT 21s left n/a n/a test-timer.timer test-timer.target
After the first run, NEXT
and LEFT
have been replaced with n/a
:
NEXT LEFT LAST PASSED UNIT ACTIVATES
n/a n/a Fri 2021-10-08 10:38:32 EDT 1min 5s ago test-timer.timer test-timer.target
I've also tried adding Persistent=true
to the test-timer.target
and explicitly enabling test-timer.target
, but neither of these work. Any time I do systemctl restart test-timer.timer
, it restarts, but only triggers one run, then never has another go.
If I remove the layer of indirection by changing the Unit=
line of test-timer.timer
to Unit=test-timer.service
, the service happily triggers itself every minute as expected.
Am I missing some configuration or installation step?