[systemd-devel] Cannot get Shutdown Script to Run (Libvirt Virtual Machine Shutdown)

Lennart Poettering lennart at poettering.net
Fri Oct 10 02:20:38 PDT 2014


On Thu, 09.10.14 20:28, Jóhann B. Guðmundsson (johannbg at gmail.com) wrote:

> 
> On 10/09/2014 02:26 PM, Lennart Poettering wrote:
> >On Thu, 09.10.14 12:14, Jóhann B. Guðmundsson (johannbg at gmail.com) wrote:
> >
> >>On 10/08/2014 11:41 PM, Lennart Poettering wrote:
> >>>TODO list to allow services also when they have no ExecStart= but with
> >>>an ExecStop=, but this has not been implemented yet.
> >>What's the usecase for this behaviour?
> >Precisely cases like the one described earlier in this thread: when
> >you want to run something only at shutdown, properly ordered against
> >other units that are also shut down.
> 
> To me that already works just fine.
> 
> [Unit]
> Description=My Shutdown Test
> Before=shutdown.target
> DefaultDependencies=no
> 
> [Service]
> Type=oneshot
> ExecStart=/bin/systemd-cat -t "SHUTDOWN" /bin/echo "Systemd shutdown test-2"
> 
> [Install]
> WantedBy=shutdown.target


It's not that easy. Note that in systemd we have the rule that if two
units are ordered against each other, and one is started and one is
stopped the stop will always be executed first, the start second,
regardless if the actual ordering is After= or Before=. Now, this
means unless you want to run your code only after some other service
shut down, everything is good. But if you want your code to run before
some other unit is shut down, then you cannot express this with a
service that is started at shutdown.

Thus the recommended way to implement services that are execute right
at the appropriate place in the shutdown order is to make it a service
that is a NOP at start, and only contains ExecStop=.

It's not particularly pretty, but not that bad either. And better than
the other options we saw...

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list