[systemd-devel] Having my script blocking all other scripts until it ends

Lennart Poettering lennart at poettering.net
Wed Oct 14 09:22:32 PDT 2015

On Thu, 24.09.15 10:15, Luca Bertoncello (L.Bertoncello at queo-group.com) wrote:

> Hi again!
> So, I got my script starting "as first" (or at least before other services), but the problem is, that the other services, needed from my script, will be shutted down before my script ends...
> So the question: how can I have my script BLOCK all other processes
> until it ends?

You cannot. You have to order your service explicitly "Before=" all
services you you wanted to be run before. THis then implies an
ordering at shutdown too, as the shutdown order is always the reverse
of the start-up order in systemd.

THere's no concept of running things "first" or "last" during boot-up
or shutdown, and there's no concept of freezing execution of other
units if yours is running, as that would be pretty weirdly defined in
a mostly parallel scheme like systemd where connecting to another
service or invoking another method on another service might result in
automatic activation.

Hence: figure out exactly what you want to be ordered after at boot
and place that in the After= line in the unit file. THen figure out
what you want to be ordered before, and add Before= lines for
that. THen, look at your shutdown, and order yourserlves After=
everything that you want to be stopped before, due to the
reverse-order-at-shutdown rule...


Lennart Poettering, Red Hat

More information about the systemd-devel mailing list