[systemd-devel] systemd update "forgets" ordering for shutdown

Michael Chapman mike at very.puzzling.org
Sun May 17 00:32:46 UTC 2020


On Fri, 15 May 2020, Frank Steiner wrote:
> Hi,
> 
> I need to run a script on shutdown before any other service is stopped.
> Due to an advice Lennart gave a while ago I'm using this service file
> (with multi-user.target being our default runlevel target):
> 
> [Unit]
> After=multi-user.target
> 
> [Service]
> Type=oneshot
> ExecStart=/bin/true
> ExecStop=/usr/lib/systemd/scripts/halt.local.bio
> TimeoutSec=120
> RemainAfterExit=yes

This seems inherently fragile.

If `multi-user.target` were to be stopped for whatever reason (and this 
is generally possible), the ordering dependencies between services 
Before=multi-user.target and services After=multi-user.target are broken. 
This is because no stop job for `multi-user.target` will be added to 
systemd's transaction (it's already stopped!), and ordering dependencies 
only apply to units actually added to the transaction.

I saw that you noted that the problem started after `systemctl 
daemon-reload`. Perhaps you could check whether `multi-user.target` is 
still active after this?

(Thinking about this some more, this seems like an inherent design flaw 
with the way all of the systemd's standard targets work. Perhaps these 
ought to use RefuseManualStop=true? Perhaps this should even be the 
default?)


More information about the systemd-devel mailing list