[systemd-devel] How to lock two instances of a templated service against each other

Marc Haber mh+systemd-devel at zugschlus.de
Tue Jul 29 08:30:49 UTC 2025


Hi,

I have a template service unit which runs a oneshot service that 
generates both high CPU and high I/O load for a couple of minutes. The 
service is templated a couple of times and runs from an, also templated 
timer.

In another use case, I have independent services that generate high CPU 
and high I/O.

In both cases, it has been measured that total processing time is 
quicker when one lets the jobs run one after the other instead of having 
them conurrently compete over same set of resources. The measurement 
results are even more clear when the data is stored on HDDs due to head 
movement and disk rotation latency.

I would like to lock them against each other that only one of those 
services runs concurrently at a time, and other instances that might 
have been requested while one is still running are delayed until 
everyhing is "free". Missing a job because one other is already running 
would be a bug.

The solution one finds on the net is to use flock(1) in the ExecStart* 
options, often making wrapper scripts necessary. I find this clumsy and 
un-systemd-like and would not like to do that.

Does systemd offer a better solution for this?

Greetings
Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Leimen, Germany    |  lose things."    Winona Ryder | Fon: *49 6224 1600402
Nordisch by Nature |  How to make an American Quilt | Fax: *49 6224 1600421


More information about the systemd-devel mailing list