1

I have a realtime timer with Persistent=false running immediately after boot although my objective is to run it periodically!
I saw it is a rather common question but none of the answers I found in StackExchange solved my issue. I followed the advices of this post and this post.

Here I report a simplified example to reproduce my issue. I want the timer to be executed every 5 minutes (0,5,10,15,...55) but not after boot.

I have the following two files, generated using
sudo systemctl edit --force --full test.service and
sudo systemctl edit --force --full test.timer

# test.service
[Unit]
Description=test

[Service]
Type=simple
ExecStart=echo "TEST"

# test.timer
[Unit]
Description=test

[Timer]
OnCalendar=*:0/5
Persistent=false

[Install]
WantedBy=default.target

Then I made sure to disable the service using:
sudo systemctl disable test.service
and enabled the timer using:
sudo systemctl enable test.timer

Now, when running sudo reboot, the test.service is immediately executed.
journalctl -u test looks like:

-- Journal begins at Thu 2023-08-24 02:39:59 UTC, ends at Thu 2023-08-24 19:40:14 UTC. --
Aug 24 19:33:02 rbpi0 systemd[1]: Started test.
Aug 24 19:33:02 rbpi0 echo[463]: TEST
Aug 24 19:33:03 rbpi0 systemd[1]: test.service: Succeeded.
Aug 24 19:35:14 rbpi0 systemd[1]: Started test.
Aug 24 19:35:14 rbpi0 echo[911]: TEST
Aug 24 19:35:14 rbpi0 systemd[1]: test.service: Succeeded.
Aug 24 19:40:14 rbpi0 systemd[1]: Started test.
Aug 24 19:40:14 rbpi0 echo[1352]: TEST
Aug 24 19:40:14 rbpi0 systemd[1]: test.service: Succeeded.

And you can clearly see the test.service has been executed at 19:33 at boot...

Has someone any Idea where the mistake could be?

Edit 1

I tried to change the [Install] section:

  • Attempt 1: Removed completely the [Install] section.
    Result:
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template units). 
This means they are not meant to be enabled using systemctl.
  • Attempt 2: changed WantedBy=default.target to WantedBy=timer.target or WantedBy=multi-user.target
    Result: same issue.

Edit 2

By reading the timer manual page I noticed I needed to be sure the system clock is synced before time-sync.target. I made sure the clock is synced but the issue remains.

2
  • Try removing the Install section from the timer file. WantedBy=default.target will cause it to fire when the system comes up. I believe the default for a timer with no install is the same as if it had an Install section with After time-set.target and time-sync.target but you should check your system to be sure the system timer is sync'ed before timer tasks are started.
    – user103944
    Commented Aug 25, 2023 at 23:17
  • Your idea is not working for me: when I disable and enable the timer after the I get: The unit files have no installation config (WantedBy=, RequiredBy=, Also=, Alias= settings in the [Install] section, and DefaultInstance= for template units). This means they are not meant to be enabled using systemctl.
    – Pa Dalton
    Commented Aug 26, 2023 at 11:54

2 Answers 2

0
  1. Timer units should have WantedBy=timer.target in their [Install] section.

  2. If you want it to start at a specific point in the boot sequence you should add derictives like Before= and/or After= etc under [Unit] in the timer and/or service units.

  3. Not sure what you mean by your differentaion of "realtime" and "periodic" im this context, because timer units are actually both where the OnCalendar= makes them "periodic".

  4. *:0/5 means activate every 5 minutes, with no specific starting time hence it starts ASAP after boot, see the output of systemd-analyze calendar --iterations=10 '*:0/5'

1
  • Thank you for your answer. I tried everything you proposed but it didn't solve the issue.
    – Pa Dalton
    Commented Nov 16, 2023 at 10:51
0

Eureka!

The issue was that I hadn't initialized the time correctly.

Yes I followed this post but I used a script that wrapped the /sbin/hwclock --hctosys --utc --noadjfile command, delaying it in time. This let the boot sequence to start already creating a mess with the OnCalendar= entry (as described in the timer manual page).

I was enough to add a service exactly as this, no need to change anything else.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .