On a KVM host I have a few VMs with legacy OSes that do not listen to ACPI shutdown event. As it happens on Debian 9.5 host, on shutdown the libvirt-guests.service
waits for 5 minutes for each such VM and then destroys it.
In order to avoid that and shut them down cleanly, I have created custom VM shutdown service, with a script that uses special methods to shut them down:
% cat /etc/systemd/system/multi-user.target.wants/vm_stop.service
[Unit]
Description=vm_shutdown
Before=libvirt-guests.service
[Service]
ExecStart=/bin/true
ExecStop=/usr/local/bin/vm_shutdown_all.sh
[Install]
WantedBy=multi-user.target
However, on shutdown the service appears to run after libvirt-guests.service
in spite of the Before=
settings in above service.
Now, I have tested that the custom service actually does run on shutdown - it touch
es a test file where I can verify it.
The problem: how do I ensure that it runs before libvirt-guests.service
?
The
Before=
statement relates to the start up of the service. Fromman systemd.unit
.So you want to configure your service with
After=libvirt-guests.service
as the service then is started afterlibvirt-guests.service
is started and your service is stopped beforelibvirt-guests.service
is stopped.