I have a unit that normally I want running, but sometimes I want to manually shut it off for the day and restart it later automatically. So I have a timer to restart it OnCalendar=daily
. This works, but sometimes I need to stop the unit twice because the timer immediately restarts the unit.
Here's a simplified example with minutes instead of days:
[Unit]
Description=foo timer
[Timer]
Persistent=false
OnCalendar=minutely
AccuracySec=1
Unit=foo.service
[Install]
WantedBy=default.target
[Unit]
Description=foo service
[Service]
Type=simple
ExecStart=/bin/sh -c 'while true; do sleep 1; done'
[Install]
WantedBy=default.target
If I systemctl stop foo.service
, and the timer had fired more than 1 minute ago (PASSED > 1m in systemdctl list-timers
), it immediately refires and starts the unit. The unit always stays stopped until the next minute if I stop it twice. The docs make it sound like Persistent=false
should not cause this, but clearly I'm misunderstanding. If it matters, the daily unit I'm actually interested in is a system unit, but the test unit is a user unit; the behavior is the same.