[systemd-devel] Stop systemd timer upon success script and restart the next day

Andrei Borzenkov arvidjaar at gmail.com
Thu May 16 05:35:57 UTC 2019


15.05.2019 23:21, Jeffrey Walton пишет:
> I have a systemd timer that starts a service, and the service executes
> a script that downloads data files once a day. Once the data files are
> retrieved I don't need the timer for the remainder of the day.
> However, I need the time again the next day.
> 
> Here are the two docs I found on scheduling a timer, but I was not
> able to parse out the info I needed.
> https://www.freedesktop.org/software/systemd/man/systemd.timer.html
> and https://www.freedesktop.org/software/systemd/man/systemd.time.html
> .
> 
> How do I specify a timer that starts 6:00 AM every morning, fires once
> an hour, and then stops for the day upon success of the download?

You do not. Timers are not aware what services they start do, nor are
they aware of "download success".

How expensive starting of service is that you need to prevent it?

I was about to suggest transient timers to simulate "at" command - your
service could schedule next run if necessary. It almost works (i.e. next
service invocation is scheduled) but it results in permanent:

мая 16 08:31:34 bor-Latitude-E5450 systemd-run[12618]: Failed to start
transient timer unit: Unit test-service.timer already exists.

For a proof of concept

[Service]
ExecStart=/bin/echo I am started
ExecStopPost=/usr/bin/systemd-run --no-block --user
--unit=test-service.service --on-unit-inactive=+5




More information about the systemd-devel mailing list