2

I have a systemd timer template [email protected] and a corresponding service [email protected]. The job runs daily and has a generous RandomizedDelaySec of 2 hours. The job has many instances.

Can I tell systemd to try not to run all instances of the templates in parallel?

The jobs have a high network load. Running them in parallel slows it down and it's more important that the job finishes quickly than running on time.

[email protected] or Conflicts=job@*.timer does not work.

[email protected]:

[Unit]
Description=Run network intensive script for %i

[Timer]
OnCalendar=daily
RandomizedDelaySec=2h
Persistent=true

[Install]
WantedBy=timers.target

[email protected]:

[Unit]
Description=Run network intensive script for %i

[Service]
Type=oneshot
ExecStart=/my/fancy/script.sh %i

1 Answer 1

1

I would probably solve this by adding an explicit lock to the service unit:

[Service]
Type=oneshot
ExecStart=/usr/bin/flock -F /path/to/some/lockfile /my/fancy/script.sh %i

This will allow only one instance of your script to run at a time; others will block until the script is complete.

1
  • Thank you. That should work. However, I'd prefer a systemd native solution. Preferably with less hard constraints. It should not be forbidden to overlap the execution of the units but systemd should try to avoid overlaps.
    – sedrubal
    Commented Jul 31, 2023 at 12:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .