How to run some service exactly every second? Overlapping allowed.
Here is my timer unit for systemd:
[Unit]
Description=Send jobs every second
[Timer]
OnBootSec=1min
OnUnitActiveSec=1s
Unit=app.jobs-send.service
[Install]
WantedBy=multi-user.target
But app.jobs-send.service
service doesn't executed every second:
May 07 17:57:38 app.deployer.org systemd[1]: Started Send jobs to queue.
May 07 17:57:48 app.deployer.org systemd[1]: Starting Send jobs to queue...
May 07 17:57:48 app.deployer.org systemd[1]: Started Send jobs to queue.
May 07 17:57:58 app.deployer.org systemd[1]: Starting Send jobs to queue...
May 07 17:57:58 app.deployer.org systemd[1]: Started Send jobs to queue.
May 07 17:58:08 app.deployer.org systemd[1]: Starting Send jobs to queue...
May 07 17:58:08 app.deployer.org systemd[1]: Started Send jobs to queue.
There is a gap about 17:57:58 - 17:57:48 = 10 seconds.
How to exec task every second?
To start the timer, use the command sudo systemctl start helloworld. timer . To enable the timer on boot, run the command sudo systemctl enable helloworld.
Systemd timers offer the best of both cron and anacron. Allows scheduling down to minute granularity. Assures that the task will be executed when the system is again running even if it was off during the expected execution time. Is available to all users.
To list all timers (including inactive), use systemctl list-timers --all . The status of a service started by a timer will likely be inactive unless it is currently being triggered.
As documented in man systemd.time, the accuracy of OnUnitActiveSec=
is subject to the AccuracySec=
setting, also documented there. Set to AccuracySec=1us
for best resolution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With