Re: [PATCH] maintenance: use systemd timers on Linux

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 01/05/21 21.52, Lénaïc Huard wrote:
The existing mechanism for scheduling background maintenance is done
through cron. On Linux systems managed by systemd, systemd provides an
alternative to schedule recurring tasks: systemd timers.

The main motivations to implement systemd timers in addition to cron
are:
* cron is optional and Linux systems running systemd might not have it
   installed.

Supposed that I have Linux box with systemd and classical cron. Should
systemd timers be preferred over cron?

* The execution of `crontab -l` can tell us if cron is installed but not
   if the daemon is actually running.
* With systemd, each service is run in its own cgroup and its logs are
   tagged by the service inside journald. With cron, all scheduled tasks
   are running in the cron daemon cgroup and all the logs of the
   user-scheduled tasks are pretended to belong to the system cron
   service.
   Concretely, a user that doesn’t have access to the system logs won’t
   have access to the log of its own tasks scheduled by cron whereas he
   will have access to the log of its own tasks scheduled by systemd
   timer.

In order to schedule git maintenance, we need two unit template files:
* ~/.config/systemd/user/git-maintenance@.service
   to define the command to be started by systemd and
* ~/.config/systemd/user/git-maintenance@.timer
   to define the schedule at which the command should be run.

Those units are templates that are parametrized by the frequency.

Based on those templates, 3 timers are started:
* git-maintenance@hourly.timer
* git-maintenance@daily.timer
* git-maintenance@weekly.timer

The command launched by those three timers are the same than with the
other scheduling methods:

git for-each-repo --config=maintenance.repo maintenance run
--schedule=%i

with the full path for git to ensure that the version of git launched
for the scheduled maintenance is the same as the one used to run
`maintenance start`.

The timer unit contains `Persistent=true` so that, if the computer is
powered down when a maintenance task should run, the task will be run
when the computer is back powered on.

Signed-off-by: Lénaïc Huard <lenaic@xxxxxxxxx>
Nevertheless, because we are dealing with external dependency (systemd), it
should makes sense to enforce this dependency requirement when user choose to use
systemd timers so that users on non-systemd boxes (such as Gentoo with OpenRC)
don't see errors that forcing them to use systemd.

--
An old man doll... just what I always wanted! - Clara



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux