[systemd-devel] Running a script as FIRST script before shutdown

Lennart Poettering lennart at poettering.net
Thu Sep 24 05:48:59 PDT 2015


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

> Hi Lennart,
> 
> thank you for your answer!
> 
> > There is no concept of "first" or "last" in systemd, since it's not clear what
> > that's supposed to mean if there are multiple, and what happens if some
> > operation results in activation?
> 
> That's bad... :)
> 
> > Hence, simply order your service against the services it requires. If you want
> > to just run some code when shutting down, make it a service with
> > Type=oneshot and RemainAfterExit=yes, give it an empty ExecStart=, but
> > specify ExecStop= to whatever it's supposed to do. Then order it *after* the
> > services that it shall be able to use, as the shutdown order in systemd is
> > always the inverse of the startup order, and what you specify via After= and
> > Before= specifies the startup order.
> 
> Well, this is what I tried for more the three days... :(
> I know, that the script need at least vdsmd.service, vdsm-network.service and libvirtd.service.
> But it needs that the tmpfs-partition /run is mounted, too.

/run itself is mounted as tmpfs by PID 1 very early on. Much like /sys
or /proc it's considered an API file system, and thus unconditionally
available.

If systemd is used this implies that /run is mounted as a tmpfs, and
that is done before the first userspace process that's not PID 1 is
started.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list