You are not logged in.
Pages: 1
I am trying to do something that I thought should be very simple, configure a simple service to run every minute or so. The issue is no matter what permutation of the timer I tried using it either doesn't run at all or just runs 1 time. At the current config if I stop and then start the timer it counts down as expected and runs the service but the stops. Restarting the timer doesn't even run once. Service unit is not enabled or started. Timer is set to enabled and started. I tried OnBootSec, OnActiveSec and OnUnitActiveSec in the timer with similar results. I did run systemctl --user daemon-reload after each change. I am starting timer/service with --user option. The service runs fine on it's own, it's the timer that doesnt run. Systemd manual doesn't shed light on this and I don't see any special config requirements for --user timers. What could I be missing here?
Service:
cat /etc/systemd/user/owncloud-sync.service
[Unit]
Description=ownCloud Sync Service
[Service]
Type=oneshot
ExecStart=/usr/bin/owncloudcmd --non-interactive -h -u dom -p ********** /mnt/homes/%u/ownCloud/ url
[Install]
WantedBy=default.target
Timer:
cat /etc/systemd/user/owncloud-sync.timer
[Unit]
Description=ownCloud Sync Timer (runs every ...)
[Timer]
OnBootSec=30s
[Install]
WantedBy=timers.target
Timer status:
systemctl --user list-timers -all
NEXT LEFT LAST PASSED UNIT ACTIVATES
n/a n/a Tue 2017-10-31 10:35:10 GMT 4min 41s ago owncloud-sync.timer owncloud-sync.service
Last edited by dominicm (2017-10-31 10:51:18)
Offline
You need to use OnCalendar= instead.
All of the options you tried performed exactly as documented, you need to read...
man 5 systemd.timer
Offline
You need to use OnCalendar= instead.
All of the options you tried performed exactly as documented, you need to read...
man 5 systemd.timer
I read that fully but I don't think you have. OnCalendar is not what I want at all. I don't need realtime I just need it to run every x seconds, doesn't really matter if it's from timer start (OnActiveSec), from boot (OnBootSec / OnStartupSec) or other. OnActiveSec for example should run every x seconds after timer was started, don't know how this could be misinterpreted to mean something completely different.
Offline
OnActiveSec=, OnBootSec=, OnStartupSec=, OnUnitActiveSec=, OnUnitInactiveSec=
Defines monotonic timers relative to different starting points: OnActiveSec= defines a timer relative to the moment the timer itself is activated.
OnBootSec= defines a timer relative to when the machine was booted up. OnStartupSec= defines a timer relative to when systemd was first started.
OnUnitActiveSec= defines a timer relative to when the unit the timer is activating was last activated. OnUnitInactiveSec= defines a timer relative to when
the unit the timer is activating was last deactivated.
Where do you get the idea that any of these ever repeat?
For a repeating timer you need to use OnCalendar, for example running the service every minute would require...
OnCalendar=*-*-* *:*:00
or
OnCalendar=minutely
Last edited by Slithery (2017-10-31 11:38:30)
Offline
Hmm, taht so annoying that it doesnt' explicitly say it runs ONCE. It's really strange since I used multiple timers before with no OnCalendar and they worked as expected. Maybe I just got lucky that the frequency of startup was sufficient... Still OnCalendar just seems wrong to use for timple repeating intervals, a simple repeat=yes option would make much more sense to me than a complicated cron-like OnCalendar option...
I am sure it will work will test it out later, thanks for the explanation!
Offline
Slithery, they do repeat. This is made explicit in an example in the wiki:
https://wiki.archlinux.org/index.php/Sy … onic_timer
I have a timer for mbsync with OnBootSec and OnUnitActiveSec, no OnCalendar. It repeats every 5 minutes as intended.
You can also see an example distributed with systemd itself at /usr/lib/systemd/system/systemd-tmpfiles-clean.timer the description says it repeats daily, but it uses OnUnitActiveSec not OnCalendar.
EDIT: note however, dominicm, you said you tried OnBootSec and OnUnitActiveSec, but did you try them both together? That is what is required: OnBootSec defines the first run, OnUnitActiveSec is from the last time the target unit was activated, but if you only have the latter, the unit will never be activated and thus never reach a time after it has been last activated.
Last edited by Trilby (2017-10-31 11:56:11)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Offline
Note the edit - they don't automagically repeat at the interval, rather they will continue to repeat so long as their triggering event does. OnBootSec is triggered by booting, obviously that doesn't repeat. But the OnActive* ones can repeat if the Active state repeats - but if it is never triggered in the first place it will not be active and thus never even start the repeats: hence the need for OnActiveSec to be paired with something like OnBootSec.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Slithery, they do repeat. This is made explicit in an example in the wiki:
https://wiki.archlinux.org/index.php/Sy … onic_timerI have a timer for mbsync with OnBootSec and OnUnitActiveSec, no OnCalendar. It repeats every 5 minutes as intended.
You can also see an example distributed with systemd itself at /usr/lib/systemd/system/systemd-tmpfiles-clean.timer the description says it repeats daily, but it uses OnUnitActiveSec not OnCalendar.
EDIT: note however, dominicm, you said you tried OnBootSec and OnUnitActiveSec, but did you try them both together? That is what is required: OnBootSec defines the first run, OnUnitActiveSec is from the last time the target unit was activated, but if you only have the latter, the unit will never be activated and thus never reach a time after it has been last activated.
Thanks for restoring my sanity The timers I used before do indeed have both options. What I don't get is why OnActiveSec alone doesn't work since it should start counting from when the timer starts? OnBootSec and OnUnitActiveSec is not ideal as it requires reboot (maybe) and it's 2 options instead of one though I know I am being picky here.
Offline
What I don't get is why OnActiveSec alone doesn't work since it should start counting from when the timer starts?
Yes, but just like OnBootSec that only happens once. For a repeating timer, the timer unit starts only once, the target unit may start many times. So the criteria of an offset of say 30 seconds from the timer start will only happen once while an offset of 30 seconds from the target unit start can happen many times.
OnBootSec=30 will only trigger once, 30 seconds after booting.
OnUnitActiveSec=30 will either trigger zero times if nothing else starts the target unit, or it will trigger repeatedly every 30 seconds once something else starts the target service.
OnActiveSec=30 I suspect behaves just like OnBootSec but is relative to the timer activation: it will only trigger once.
OnBootSec and OnUnitActiveSec is not ideal as it requires reboot (maybe) and it's 2 options instead of one though I know I am being picky here.
Two options are necessary for what you want: one to say when to start, and one to say how often to repeat. If you want only one options, then you could use OnCalendar. OnUnitActiveSec defines how often it repeats only, but it is not sufficient to start it. You can add another trigger to start: OnBootSec is easy for something you always want running, but you could use OnActiveSec if you want to activate the timer manually (which it's sounding like you do).
You could even use just one option of OnUnitActiveSec and just enable the timer and the target unit at the same time. The timer will then take care of the repetitions, but you'll have manually run the target unit to start the series.
Last edited by Trilby (2017-10-31 12:42:43)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
That's some convoluted logic there but I get it. I went with OnStartupSec becaue it seems like OnBootSec actually requires reboot to start but OnStartupSec starts on timer start. Minor detail but I din't feel like rebooting the server Can't find any info on exactly how they function though.
OnStartupSec=1m
OnUnitActiveSec=1m
Offline
Can't find any info on exactly how they function though.
What do you mean? The man page describes each of them. The names themselves are even quite descriptive. What information do you think you are lacking?
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
dominicm wrote:Can't find any info on exactly how they function though.
What do you mean? The man page describes each of them. The names themselves are even quite descriptive. What information do you think you are lacking?
I mean it's not clear how it functions under the hood. That is does it use stored time of boot or does it only activate live on boot. OnStartupSec seems to store the value in some way while onBootSec doesn't seem to do so. The difference between the two is also not explained as far as I can see.
Offline
@Trilby Would it be helpful to add some of what you explained above to the wiki https://wiki.archlinux.org/index.php/Systemd/Timers? To make it more explicit why the monotonic timer needs 2 options, whereas the realtime one does not?
CLI Paste | How To Ask Questions
Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L
Offline
Feel free. The current example seems clear and concise to me. Certainly I'd not assume this would be crystal clear to everyone, but as it is to me, I'm not really equipped to know how it should be editted. If the current wiki example(s) are not clear to you, you are more suited to know what it would take to make them so.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Pages: 1