Posts: 1
Joined: Sat Mar 16, 2019 3:25 pm

Creating systemd timers on boot

Sat Mar 16, 2019 3:44 pm

Man I miss cron. I've had a tough time in the past getting systemd boot scripts to run at precisely the right time at boot, but now I'm at a total loss with timers.

This should be simple. I'm trying to get a .sh file to run on a timer at boot. The forum postings on timers across multiple boards are inconsistent, and Raspbian seems to have its own quirks about where you [Install] your service/timer that vary from other distributions. Moreover if I run the timer by hand it works... but when I reboot it does nothing. There doesn't seem to be a good step-by-step tutorial anywhere for how to create and install a timer on boot on ANY distribution, and the fact that the .service and .timer files work properly when manually started makes me all the more frustrated. It has to be something simple that I'm not doing.

So my question is just that. Can someone walk me through every step - not skipping a line - for how to run /usr/pi/foo.sh every 120 seconds after boot? I could post the 25 different things I've tried so far, but for such an easy task I figure this would be the easiest way of asking. For the purposes of this script, the launch timing doesn't matter - but close to the end of boot or after boot is ideal.

Thank you for your help.

Posts: 2412
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Creating systemd timers on boot

Sat Mar 16, 2019 6:04 pm

I hate both system.d and cron - give me a GUI scheduler that runs over multiple machines (I had one of those for Windows) but anyway.

I got good hints from https://coreos.com/os/docs/latest/sched ... imers.html

You may have to cheat though and create a program to issue systemctl start date.timer after all the system is up :oops: :o :oops:
Need Pi spray - these things are breeding in my house...

Posts: 5637
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Creating systemd timers on boot

Sun Mar 17, 2019 9:46 am

I still use cron on raspbian stretch for running programs at scheduled times.

Cron is still running so if you prefer it for scheduling tasks then you can still use it.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Posts: 2646
Joined: Thu May 05, 2016 9:33 am
Location: Paris, France

Re: Creating systemd timers on boot

Sun Mar 17, 2019 10:59 am

I often use the watchdog as a monotonic timer.
On a machine without RTC and with NTP, “120 secs after boot” may happen before that duration has actually elapsed due to system clock sync.
"S'il n'y a pas de solution, c'est qu'il n'y a pas de problème." Les Shadoks, J. Rouxel

Return to “Raspbian”