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

Lennart Poettering lennart at poettering.net
Wed Sep 23 07:51:38 PDT 2015


On Wed, 23.09.15 16:20, Luca Bertoncello (L.Bertoncello at queo-group.com) wrote:

> Hi list!
> 
> I'm new here and I hope, I'm in topic... I don't want to develop system, but I didn't found a "system-user"-ML...
> 
> So, to my problem:

> I need a possibility to call a script on shutdown/reboot/halt (I use
> CentOS 7). This **MUST** be the first one be called, since it needs
> many other service to be running...  The second important thing is,
> that the shutdown-process has to wait until my script ends.

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?

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.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list