Difference between revisions of "Talk:Systemd/Timers"

From ArchWiki
Jump to navigation Jump to search
(→‎Counterproductive Suggestions: Updated info about non-working service file and deleted useless striked bits)
Line 47: Line 47:
 
:Your remarks seem to make perfect sense and are corroborated by how the old {{ic|/etc/cron.*/}} files provided by packages in [base] group 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)).
 
:Your remarks seem to make perfect sense and are corroborated by how the old {{ic|/etc/cron.*/}} files provided by packages in [base] group 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:
+
:So to sum it up:
 
:*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?);
 
:*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/}};
 
:*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/}};
:*<s>Uncertain: then the corresponding service should be activated through systemctl command</s>: See edit at the end of my comment. There is no need to specifically activate timers created this way.
 
  
 
: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}} systemd.timer service converted by Thomas Bächler. Any comments appreciated.
 
: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}} systemd.timer service converted by Thomas Bächler. Any comments appreciated.
Line 65: Line 64:
 
IOSchedulingPriority=7
 
IOSchedulingPriority=7
 
</nowiki>}}
 
</nowiki>}}
 +
 +
{{Note|As for now this service file doesn't work. See my edit below for error log. {{ic|systemd}} gurus, your corrections are welcome.}}
  
 
{{hc|/usr/lib/systemd/system/reflector.timer|<nowiki>
 
{{hc|/usr/lib/systemd/system/reflector.timer|<nowiki>
Line 79: Line 80:
 
  # ln -s /usr/lib/systemd/system/reflector.timer /usr/lib/systemd/system/multi-user.target.wants/reflector.timer
 
  # ln -s /usr/lib/systemd/system/reflector.timer /usr/lib/systemd/system/multi-user.target.wants/reflector.timer
  
<s>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|logrotate}}, {{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).</s>
+
If the above is correct, this will lead to quite a massive overhaul of the wiki page... Waiting for other comments to proceed.
-- '''Edit 2014-05-12:''' I confirm it doesn't need specific activation, since after implementing this on 2014.5.8 my mirrorlist was updated on 2014.5.11. So the method seems to work properly.
+
 
 +
'''Edit 2014-05-13''': the example service file I wrote for Reflector doesn't work. I get a failed status with systemctl:
 +
{{hc|# systemctl status -l reflector|<nowiki>
 +
● reflector.service - Update pacman mirrorlist
 +
  Loaded: loaded (/usr/lib/systemd/system/reflector.service; static)
 +
  Active: failed (Result: exit-code) since mer. 2014-05-14 00:00:10 CEST; 49min ago
 +
  Process: 6149 ExecStart=/usr/bin/reflector --protocol http --latest 5 --sort rate --save /etc/pacman.d/mirrorlist (code=exited, status=1/FAILURE)
 +
Main PID: 6149 (code=exited, status=1/FAILURE)
 +
 
 +
mai 14 00:00:10 arch-clevo reflector[6149]: error: failed to retrieve mirror data: (The read operation timed out)
 +
mai 14 00:00:10 arch-clevo systemd[1]: reflector.service: main process exited, code=exited, status=1/FAILURE
 +
mai 14 00:00:10 arch-clevo systemd[1]: Failed to start Update pacman mirrorlist.
 +
mai 14 00:00:10 arch-clevo systemd[1]: Unit reflector.service entered failed state.</nowiki>}}
  
If the above is correct, this will lead to quite a massive overhaul of the wiki page... Waiting for other comments to proceed.
+
Does anyone know how I should edit this file? I'll be trying different options taken from {{ic|systemd.service}} manpage, but if somebody is knowledgeable enough to spare us some time that's all right too...
-- [[User:Neitsab|Neitsab]] ([[User talk:Neitsab|talk]]) 11:44, 8 May 2014 (UTC) -- Edit 14:12, 12 May 2014 (UTC)
+
 
 +
-- [[User:Neitsab|Neitsab]] ([[User talk:Neitsab|talk]]) 11:44, 8 May 2014 (UTC), '''edited''' 23:25, 13 May 2014 (UTC)
  
 
:Well, I would say that it is a better idea to wait before editing this page. Falconindy, I remember some talk about AccuracySec not working properly on the [https://mailman.archlinux.org/pipermail/arch-general/2014-April/036019.html arch-general ML]. Has it been dealt with? - [[User:Genghizkhan91|Genghizkhan91]] ([[User talk:Genghizkhan91|talk]]) 05:41, 13 May 2014 (UTC)
 
:Well, I would say that it is a better idea to wait before editing this page. Falconindy, I remember some talk about AccuracySec not working properly on the [https://mailman.archlinux.org/pipermail/arch-general/2014-April/036019.html arch-general ML]. Has it been dealt with? - [[User:Genghizkhan91|Genghizkhan91]] ([[User talk:Genghizkhan91|talk]]) 05:41, 13 May 2014 (UTC)

Revision as of 23:26, 13 May 2014

Monthly events

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.

Only modifications -- apart from substituting "weekly" by "monthly" everywhere relevant -- seem to be in the [Timer] section:

/etc/systemd/system/timer-monthly.timer
[Unit]
Description=Monthly Timer

[Timer]
OnBootSec=20min
OnUnitActiveSec=1month
Unit=timer-monthly.target

[Install]
WantedBy=basic.target
/etc/systemd/system/timer-monthly.target
[Unit]
Description=Monthly Timer Target
StopWhenUnneeded=yes

If that seems ok to you I'll add it and update mkdir/systemctl instructions accordingly.

Neitsab (talk) 18:47, 12 January 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)

Removing my previous suggestion as 1) monthly events have been merged into the main article and 2) Falconindy's remarks below indicate the overall method was incorrect. If a wiki mod wants to delete this section, please process.

Neitsab (talk) 12:43, 8 May 2014 (UTC)

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] group 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:
  • 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/;
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 systemd.timer service converted by Thomas Bächler. Any comments appreciated.
Step one: create timer and service files for every different unit
/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
Note: As for now this service file doesn't work. See my edit below for error log. systemd gurus, your corrections are welcome.
/usr/lib/systemd/system/reflector.timer
[Unit]
Description=Daily update of pacman mirrorlist

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

If the above is correct, this will lead to quite a massive overhaul of the wiki page... Waiting for other comments to proceed.

Edit 2014-05-13: the example service file I wrote for Reflector doesn't work. I get a failed status with systemctl:

# systemctl status -l reflector
● reflector.service - Update pacman mirrorlist
   Loaded: loaded (/usr/lib/systemd/system/reflector.service; static)
   Active: failed (Result: exit-code) since mer. 2014-05-14 00:00:10 CEST; 49min ago
  Process: 6149 ExecStart=/usr/bin/reflector --protocol http --latest 5 --sort rate --save /etc/pacman.d/mirrorlist (code=exited, status=1/FAILURE)
 Main PID: 6149 (code=exited, status=1/FAILURE)

mai 14 00:00:10 arch-clevo reflector[6149]: error: failed to retrieve mirror data: (The read operation timed out)
mai 14 00:00:10 arch-clevo systemd[1]: reflector.service: main process exited, code=exited, status=1/FAILURE
mai 14 00:00:10 arch-clevo systemd[1]: Failed to start Update pacman mirrorlist.
mai 14 00:00:10 arch-clevo systemd[1]: Unit reflector.service entered failed state.

Does anyone know how I should edit this file? I'll be trying different options taken from systemd.service manpage, but if somebody is knowledgeable enough to spare us some time that's all right too...

-- Neitsab (talk) 11:44, 8 May 2014 (UTC), edited 23:25, 13 May 2014 (UTC)

Well, I would say that it is a better idea to wait before editing this page. Falconindy, I remember some talk about AccuracySec not working properly on the arch-general ML. Has it been dealt with? - Genghizkhan91 (talk) 05:41, 13 May 2014 (UTC)