2

Maybe I'm misunderstanding how "oneshot" services are handled by associated timers. Here's a dummy unit and a timer supposed to trigger it every 5' (on systemd-247.3-7+deb11u1):

# systemctl cat dummy.timer dummy.service # /etc/systemd/system/dummy.timer [Unit] Description=Trigger dummy service every 5' [Timer] OnCalendar=*:0/5 Persistent=true [Install] WantedBy=timers.target # /etc/systemd/system/dummy.service [Unit] Description=dummy one-shot service for timer testing [Service] Type=oneshot RemainAfterExit=yes ExecStart=echo "Dummy start" ExecStop=echo "Dummy stop" [Install] WantedBy=multi-user.target 

The dummy service is not a daemon but it is supposed to change the system's state, hence the reason for RemainAfterExit and for ExecStop to rollback the effects of repeated system updates made by ExecStart.

At first, everything looks fine:

# systemctl start dummy.timer dummy.service ... # systemctl status dummy.timer dummy.service ● dummy.timer - Trigger dummy service every 5' Loaded: loaded (/etc/systemd/system/dummy.timer; disabled; vendor preset: enabled) Active: active (waiting) since Fri 2023-04-07 21:05:39 CEST; 1s ago Trigger: Fri 2023-04-07 21:10:00 CEST; 4min 19s left Triggers: ● dummy.service ● dummy.service - dummy one-shot service for timer testing Loaded: loaded (/etc/systemd/system/dummy.service; disabled; vendor preset: enabled) Active: active (exited) since Fri 2023-04-07 21:05:39 CEST; 1s ago TriggeredBy: ● dummy.timer Process: 1805980 ExecStart=echo Dummy start (code=exited, status=0/SUCCESS) Main PID: 1805980 (code=exited, status=0/SUCCESS) CPU: 1ms 

However, the timer doesn't fire and gets stuck in a "running" state:

# systemctl status dummy.timer dummy.service ● dummy.timer - Trigger dummy service every 5' Loaded: loaded (/etc/systemd/system/dummy.timer; disabled; vendor preset: enabled) Active: active (running) since Fri 2023-04-07 21:05:39 CEST; 35min ago Trigger: n/a Triggers: ● dummy.service ● dummy.service - dummy one-shot service for timer testing Loaded: loaded (/etc/systemd/system/dummy.service; disabled; vendor preset: enabled) Active: active (exited) since Fri 2023-04-07 21:05:39 CEST; 35min ago TriggeredBy: ● dummy.timer Process: 1805980 ExecStart=echo Dummy start (code=exited, status=0/SUCCESS) Main PID: 1805980 (code=exited, status=0/SUCCESS) CPU: 1ms Apr 07 21:05:39 myvps echo[1805980]: Dummy start # systemctl list-timers dummy NEXT LEFT LAST PASSED UNIT ACTIVATES n/a n/a Fri 2023-04-07 21:10:09 CEST 30min ago dummy.timer dummy.service 

It looks like the timer doesn't understand "active (exited)" as terminated. Am I trying something impossible? Otherwise there something fishy.

1 Answer 1

0

It looks like the timer doesn't understand "active (exited)" as terminated.

Because the unit is active. Whether the process has terminated is irrelevant to timers; what matters is whether the unit as a whole is still in the "active" state, which means it cannot be activated again – at least not without stopping it first.

Of course, the unit remains in "active" state because you have RemainAfterExit=yes.

If you want the timer to periodically re-apply changes, you will need to remove that option and split the service into two regular oneshot services, one to apply the state and another to un-apply it.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.