[systemd-devel] "semaphore" for .timer-triggered run

Jérémy ROSEN jeremy.rosen at smile.fr
Tue Aug 27 12:45:48 UTC 2019


Out of curiosity, and to check if I understand the systemd concepts
properly...

assuming the two units to lock are both systemd services and are both of
type oneshot, would a simple After= of one on the other be enough to
guarantee they never run together ?

Le mar. 27 août 2019 à 12:56, Lennart Poettering <lennart at poettering.net> a
écrit :

> On Fr, 02.08.19 13:24, Johannes Ernst (johannes.ernst at gmail.com) wrote:
>
> > I have a oneshot .service (certbot) that is run by its .timer with:
> >
> > OnCalendar=daily
> > RandomizedDelaySec=1day
> >
> > I also have a sometimes long-running script that may modify the same
> > data. So the script and the oneshot service should never run at the
> > same time.
> >
> > Is there a good systemd pattern for some kind of semaphore-like
> > thing that will delay the execution of the oneshot service and try
> > again when the script is done running?
> >
> > I could skip execution, but then I miss an entire day until the
> > service is run again -- I’d prefer it if it tried again a few
> > minutes later. Or I could poll for some flag before running the main
> > part of the service. Wondering whether there something more
> > systemd-native.
>
> Maybe change the service program invoked by the timer unit to use file
> locking of some kind early on. I mean, if you have shared data on disk
> and want to synchronize access to it then a file lock is the concept
> of choice really. If this is a proper program (i.e. not a shell
> script) maybe just use a BSD file lock (flock(2)) on the top-level
> directory you store your data in. If these are shell scripts you
> should be able to use util-linux' flock tool, you could even prefix
> your ExecStart= line with that if you want.
>
> But no, systemd does not provide any mechanism to do file locking for
> you.
>
> Lennart
>
> --
> Lennart Poettering, Berlin
> _______________________________________________
> systemd-devel mailing list
> systemd-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/systemd-devel



-- 
[image: SMILE]  <http://www.smile.eu/>

20 rue des Jardins
92600 Asnières-sur-Seine
*Jérémy ROSEN*
Architecte technique

[image: email] jeremy.rosen at smile.fr
[image: phone]  +33 6 88 25 87 42
[image: url] http://www.smile.eu

[image: Twitter] <https://twitter.com/GroupeSmile> [image: Facebook]
<https://www.facebook.com/smileopensource> [image: LinkedIn]
<https://www.linkedin.com/company/smile> [image: Github]
<https://github.com/Smile-SA>

[image: Découvrez l’univers Smile, rendez-vous sur smile.eu]
<https://www.smile.eu/fr/publications/livres-blancs/yocto?utm_source=signature&utm_medium=email&utm_campaign=signature>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20190827/c4086a0c/attachment.html>


More information about the systemd-devel mailing list