TransWikia.com

systemd timer, how can I restart the service after power loss?

Unix & Linux Asked on November 6, 2021

I’m experiencing with systemd timers to launch a service every day at let’s say 7am. This service launch an application that must run continuously until 10pm. So if the application crashes, the service must restart it. The service is stopped at 10 by crontab, that also shutdown the system.

I’m using a timer with OnCalendar and Persistent=true which works, but I cannot ensure that if there is a power loss (system is restarted by BIOS when power is back) after 7am the service is started, because the timer already successfully triggered at 7am and so will wait until next day..

I cannot run my service at boot because if the system can start before 7am (power loss during night) and so also the service will start, I don’t want it before 7am..

Any idea?

2 Answers

Current solution I found is this.. Delete stamp file in ~/.local/share/systemd/timers. Then restart the timer.

[Source][1] "These are zero length files which mark the last time each timer was run. If deleted, they will be reconstructed on the next start of their timer."

[1]: https://wiki.archlinux.org/index.php/Systemd/Timers

I tought I've found a solution, but then realized it doesn't work when there is a powerloss after 7am...

Answered by rok on November 6, 2021

Assuming the timer is scheduled with OnCalendar, what is the last run status of the timer after such missed event? It's the LAST column of systemctl list-timers output.

If it reads 'n/a' then the timer was never triggered before, or it's last run state was cleared and so it won't be run at boot.

Answered by Tomasz Pala on November 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP