Difference between revisions of "Talk:Systemd/Timers"

From ArchWiki
Jump to navigation Jump to search
(Removing obsolete "monthly events" section and proposing new redaction following Falconindy remarks)
Line 1: Line 1:
=== Monthly events ===
+
=== Regarding OnBootSec ===
Is there any specific reason why "monthly" timing isn't presented? A limitation in systemd workings or whatever? I was more feeling like setting the "pkgstats.service" to run once a month, this is how I realized I hadn't created such folder by following the article.
+
 
 +
Do you think this option is needed anymore with the coming of the "Persistent" option in systemd 212? - [[User:Genghizkhan91|Genghizkhan91]] ([[User talk:Genghizkhan91|talk]]) 08:44, 1 April 2014 (UTC)
 +
 
 +
== Counterproductive Suggestions ==
 +
 
 +
The suggestions on this page are counterproductive. By merging all units under a single target, you're intentionally creating a stampede when the timer goes off. One of the great features of timer units is that a combination of OnCalendar and AccuracySec can trivially mitigate the overlap that's associated with classic cron while still maintaining regularity. This is distinctly better than classic cron which would force a human to schedule the task jitter manually.
 +
 
 +
In addition, it isn't reasonable to queue these on basic.target as one wants a fully operational system before cron will run. Much like how cron daemons were treated like any other daemon and brought up in runlevel 3 under sysvinit, it makes much more sense to order timers on multi-user.target. [[User:Falconindy|Falconindy]] ([[User talk:Falconindy|talk]]) 23:38, 4 May 2014 (UTC)
 +
 
 +
:Your remarks seem to make perfect sense and are corroborated by how the old {{ic|/etc/cron.*/}} files provided by packages in [base] were converted to systemd.timer files (see https://mailman.archlinux.org/pipermail/arch-dev-public/2014-March/026044.html and files present on one's system)).
 +
 
 +
:So to sum it up, before editing the wiki:
 +
:*A different {{ic|/usr/lib/systemd/system/*.{timer,service}}} couple for every unit wanted should be created (or should {{ic|/etc/systemd/system/}} be used instead?);
 +
:*Then a symbolic link to each custom {{ic|/usr/lib/systemd/system/*.timer}} file should be made in {{ic|/usr/lib/systemd/system/multi-user.target.wants/}};
 +
:*Uncertain: then the corresponding service should be activated through {{ic|systemctl}} command.
  
Only modifications -- apart from substituting "weekly" by "monthly" everywhere relevant -- seem to be in the [Timer] section:
+
:I've had a go at it for the {{Pkg|reflector}} service that I was running as a daily (ana)cron job, taking after the new {{ic|logrotate}} system.timer service converted by Thomas Bächler. Any comments appreciated.
{{hc|/etc/systemd/system/timer-monthly.timer|<nowiki>
+
===== Step one: create timer and service files =====
 +
{{hc|/usr/lib/systemd/system/reflector.service|<nowiki>
 
[Unit]
 
[Unit]
Description=Monthly Timer
+
Description=Update pacman mirrorlist
  
[Timer]
+
[Service]
OnBootSec=20min
+
Type=oneshot
OnUnitActiveSec=1month
+
ExecStart=/usr/bin/reflector --protocol http --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
Unit=timer-monthly.target
+
Nice=19
 
+
IOSchedulingClass=best-effort
[Install]
+
IOSchedulingPriority=7
WantedBy=basic.target
 
 
</nowiki>}}
 
</nowiki>}}
  
{{hc|/etc/systemd/system/timer-monthly.target|<nowiki>
+
{{hc|/usr/lib/systemd/system/reflector.timer|<nowiki>
 
[Unit]
 
[Unit]
Description=Monthly Timer Target
+
Description=Daily update of pacman mirrorlist
StopWhenUnneeded=yes
+
 
 +
[Timer]
 +
OnCalendar=daily
 +
AccuracySec=12h
 +
Persistent=true
 
</nowiki>}}
 
</nowiki>}}
  
If that seems ok to you I'll add it and update mkdir/systemctl instructions accordingly.
+
===== Step 2: make the symbolic link =====
 +
# ln -s /usr/lib/systemd/system/reflector.timer /usr/lib/systemd/system/multi-user.target.wants/reflector.timer
 +
 
 +
As to step 3, I'm not sure whether it gets activated by the sole effect of being in {{ic|multi-user.target.wants}} or if it needs separate activation ({{ic|logrotat}}, {{ic|man-db}}, {{ic|updatedb}} and {{ic|shadow}} timers are loaded, active and waiting on my system without me having touched anything related to them).
 +
 
 +
If the above is correct, this will lead to quite a massive overhaul of the wiki page... Waiting for comments here before proceeding!
 +
-- [[User:Neitsab|Neitsab]] ([[User talk:Neitsab|talk]]) 12:44, 8 May 2014 (UTC)
 +
 
 +
== Obsolete/waiting for deletion ==
 +
=== Monthly events ===
 +
Edit 2014-05-08: removing my previous suggestion as 1) monthly events have been merged into the main article and 2) Falconindy's remarks above indicate the overall method was incorrect. If a wiki mod wants to delete this section, please process.
  
[[User:Neitsab|Neitsab]] ([[User talk:Neitsab|talk]]) 18:47, 12 January 2014 (UTC)
+
[[User:Neitsab|Neitsab]] ([[User talk:Neitsab|talk]]) 18:47, 12 January 2014 (UTC) // Edited : 12:43, 8 May 2014 (UTC)
  
 
:I'd certainly use the {{ic|OnCalendar}} directive for monthly events - mainly because of this note (from [[Systemd/cron_functionality#Daily_events]]):
 
:I'd certainly use the {{ic|OnCalendar}} directive for monthly events - mainly because of this note (from [[Systemd/cron_functionality#Daily_events]]):
Line 30: Line 58:
 
:That might be usable for servers, but certainly not for for laptops/desktops. I'm using {{ic|OnCalendar}} even for weekly events, perhaps that should be changed/suggested in the article.
 
:That might be usable for servers, but certainly not for for laptops/desktops. I'm using {{ic|OnCalendar}} even for weekly events, perhaps that should be changed/suggested in the article.
 
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 17:15, 31 January 2014 (UTC)
 
:-- [[User:Lahwaacz|Lahwaacz]] ([[User talk:Lahwaacz|talk]]) 17:15, 31 January 2014 (UTC)
 
=== Regarding OnBootSec ===
 
 
Do you think this option is needed anymore with the coming of the "Persistent" option in systemd 212? - [[User:Genghizkhan91|Genghizkhan91]] ([[User talk:Genghizkhan91|talk]]) 08:44, 1 April 2014 (UTC)
 
 
== Counterproductive Suggestions ==
 
 
The suggestions on this page are counterproductive. By merging all units under a single target, you're intentionally creating a stampede when the timer goes off. One of the great features of timer units is that a combination of OnCalendar and AccuracySec can trivially mitigate the overlap that's associated with classic cron while still maintaining regularity. This is distinctly better than classic cron which would force a human to schedule the task jitter manually.
 
 
In addition, it isn't reasonable to queue these on basic.target as one wants a fully operational system before cron will run. Much like how cron daemons were treated like any other daemon and brought up in runlevel 3 under sysvinit, it makes much more sense to order timers on multi-user.target. [[User:Falconindy|Falconindy]] ([[User talk:Falconindy|talk]]) 23:38, 4 May 2014 (UTC)
 

Revision as of 11:47, 8 May 2014

Regarding OnBootSec

Do you think this option is needed anymore with the coming of the "Persistent" option in systemd 212? - Genghizkhan91 (talk) 08:44, 1 April 2014 (UTC)

Counterproductive Suggestions

The suggestions on this page are counterproductive. By merging all units under a single target, you're intentionally creating a stampede when the timer goes off. One of the great features of timer units is that a combination of OnCalendar and AccuracySec can trivially mitigate the overlap that's associated with classic cron while still maintaining regularity. This is distinctly better than classic cron which would force a human to schedule the task jitter manually.

In addition, it isn't reasonable to queue these on basic.target as one wants a fully operational system before cron will run. Much like how cron daemons were treated like any other daemon and brought up in runlevel 3 under sysvinit, it makes much more sense to order timers on multi-user.target. Falconindy (talk) 23:38, 4 May 2014 (UTC)

Your remarks seem to make perfect sense and are corroborated by how the old /etc/cron.*/ files provided by packages in [base] were converted to systemd.timer files (see https://mailman.archlinux.org/pipermail/arch-dev-public/2014-March/026044.html and files present on one's system)).
So to sum it up, before editing the wiki:
  • A different /usr/lib/systemd/system/*.{timer,service} couple for every unit wanted should be created (or should /etc/systemd/system/ be used instead?);
  • Then a symbolic link to each custom /usr/lib/systemd/system/*.timer file should be made in /usr/lib/systemd/system/multi-user.target.wants/;
  • Uncertain: then the corresponding service should be activated through systemctl command.
I've had a go at it for the reflector service that I was running as a daily (ana)cron job, taking after the new logrotate system.timer service converted by Thomas Bächler. Any comments appreciated.
Step one: create timer and service files
/usr/lib/systemd/system/reflector.service
[Unit]
Description=Update pacman mirrorlist

[Service]
Type=oneshot
ExecStart=/usr/bin/reflector --protocol http --latest 5 --sort rate --save /etc/pacman.d/mirrorlist
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7
/usr/lib/systemd/system/reflector.timer
[Unit]
Description=Daily update of pacman mirrorlist

[Timer]
OnCalendar=daily
AccuracySec=12h
Persistent=true
Step 2: make the symbolic link
# ln -s /usr/lib/systemd/system/reflector.timer /usr/lib/systemd/system/multi-user.target.wants/reflector.timer

As to step 3, I'm not sure whether it gets activated by the sole effect of being in multi-user.target.wants or if it needs separate activation (logrotat, man-db, updatedb and shadow timers are loaded, active and waiting on my system without me having touched anything related to them).

If the above is correct, this will lead to quite a massive overhaul of the wiki page... Waiting for comments here before proceeding! -- Neitsab (talk) 12:44, 8 May 2014 (UTC)

Obsolete/waiting for deletion

Monthly events

Edit 2014-05-08: removing my previous suggestion as 1) monthly events have been merged into the main article and 2) Falconindy's remarks above indicate the overall method was incorrect. If a wiki mod wants to delete this section, please process.

Neitsab (talk) 18:47, 12 January 2014 (UTC) // Edited : 12:43, 8 May 2014 (UTC)

I'd certainly use the OnCalendar directive for monthly events - mainly because of this note (from Systemd/cron_functionality#Daily_events):
"Systemd does not currently reschedule timers based on the last time they were run if the system is rebooted in between, i.e. it does not implement an anacron replacement."
That might be usable for servers, but certainly not for for laptops/desktops. I'm using OnCalendar even for weekly events, perhaps that should be changed/suggested in the article.
-- Lahwaacz (talk) 17:15, 31 January 2014 (UTC)