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
toWantedBy=timer.target
orWantedBy=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.
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.