[systemd-devel] How to keep certain services or mounts active during shutdown?

Lennart Poettering lennart at poettering.net
Fri Jul 3 03:29:12 PDT 2015


On Fri, 03.07.15 12:14, Frank Steiner (fsteiner-mail1 at bio.ifi.lmu.de) wrote:

Heya,

> > This really depends on the network management service you are
> > using. networkd won't shut down any network connections when you
> > terminate it for example.
> > 
> > Which one are you using?
> 
> it's "wicked" in SLES 12 and it really shuts the network interface down
> (might be configuration issue, though). I managed to keep it up by a 
> drop-in conf with
> ExecStop=
> ExecStop=/usr/bin/true
> (not sure if I need the second one, will check).

Yuck...

Most likely you also need KillMode=none. But this is really a hack...

Normally the network mounts should be ordered after network.target,
and wicked before that. Since in systemd the shutdown order is always
the inverse of the startup order this would mean that the mounts are
removed first, and wicked only stopped afterwards.

Then, after that you should just order the services that need your two
NFS mounts explicitly after them, so that they get stopped first, and
the NFS mounts only removed after that. You can use
RequiresMountsFor=/x/y/z to declar this dep.

> > Note though that there are actual two shutdown phases: the normal one
> > that strictly follows unit dependencies, and which you can influence
> > this way. And a final one, that then tries to clean-up everything that
> > was left over by that first phase. It's basically a umount loop that
> 
> That's ok as I only need to keep the mounts over a certain point, then
> they can go :-)

How is that "certaint point" defined? As something like "after service
foo has been shut down"? If so, then my recommendation above of adding
RequiresMountsFor= to the service sound like the much better solution.

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list