[systemd-devel] At wits end... need to execute a script prior to anything getting killed/changed on reboot/shutdown

Lennart Poettering lennart at poettering.net
Thu Jan 17 11:55:03 UTC 2019


On Mi, 16.01.19 22:44, Christopher Cox (ccox at endlessnow.com) wrote:

> On 01/16/2019 12:51 PM, Filipe Brandenburger wrote:
> > If you want to run it early in the shutdown process, then keep
> > DefaultDependencies=yes, in which case it will run before the base
> > dependencies start to get stopped.
> >
> > If you need some other resources to be up, for instance network, then
> > add After=network.target, etc.
> >
> > Remember that when shutting down, the dependencies are stopped in the
> > opposite order as they're started up, so if you need your script to run
> > *before* something else is stopped, then you need an After= dependency.
> >
> But only for services under systemd.  Everything else gets sprayed a TERM
> signal.  Which is frustrating.  So... having it execute first doesn't
> guarantee (and we're talking less than a second or so) that it will have
> time to do what it needs to do before the kill spray happens, and I need all
> processes to be around until my script finishes.

In systemd the emphasis is on defining correct deps. If you service
needs some other service to shutdown properly, then it should order
itself After= that other service, which makes sure your service is
started after that other service started up, and stops before
that other service shuts down.

In general: if you are asking for absolutes such as "stop this first"
or "start this last", then most likely the better approach would be to
track down the actual deps you need, and use those instead...

> Old sysvinit didn't have this limitation.

Well, that's not precisely true. On LSB-style sysvinit you#d have to
define deps in the sysvinit script header for ordering to work
correctly. And on sysvinit predating that you'd have to use the right
priority values compare to the services you wanted to be ordered
after. This isn't too different from systemd really, except that we
generally parallelize and sysvinit was only parallelized on some
distros.

Lennart

--
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list