[libvirt] [PATCH] shutting down guest vms on host shutdown does not work

Hi, I originally postet this into the Fedora bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=843836 but was asked by Eric to post it here for review. Currently gracefully shutting down guest vms on host shutdown does not work on Fedora 17, the guests are killed hard on system shutdown. I use: fedora-release-17-1.noarch libvirt-client-0.9.11.4-3.fc17.x86_64 systemd-44-17.fc17.x86_64 But I have looked into current libvirt git and see the same code there so I don't think it is any different with current git, but I have not verified this. The reason is systemd considers libvirt-guests.service to be stopped when the system is running: $ systemctl status libvirt-guests.service libvirt-guests.service - Suspend Active Libvirt Guests Loaded: loaded (/usr/lib/systemd/system/libvirt-guests.service; enabled) Active: deactivating (stop) since Fri, 27 Jul 2012 15:47:31 +0200; 2min 48s ago Process: 1085 ExecStart=/etc/init.d/libvirt-guests start (code=exited, status=0/SUCCESS) Control: 1150 (libvirt-guests) CGroup: name=systemd:/system/libvirt-guests.service └ control ├ 1150 /bin/sh /etc/init.d/libvirt-guests stop └ 2257 sleep 1 libvirt-guests.service is defined as type "simple" in systemd (the default). That means systemd will shut down the service when the start executable is terminated after starting is done. Systemd will not call stop again on system shutdown because it thinks it is already stopped. The solution is to define it as type "oneshot" and set the flag "RemainAfterExit". Then systemd will consider the service as active after startup and will call the stop function on host shutdown. With the attached patch everything works as expected. Please consider merging. Kind regards, Gerd

On 07/27/2012 09:01 AM, Gerd v. Egidy wrote:
Hi,
I originally postet this into the Fedora bugzilla https://bugzilla.redhat.com/show_bug.cgi?id=843836 but was asked by Eric to post it here for review.
Thanks.
Currently gracefully shutting down guest vms on host shutdown does not work on Fedora 17, the guests are killed hard on system shutdown.
I use: fedora-release-17-1.noarch libvirt-client-0.9.11.4-3.fc17.x86_64 systemd-44-17.fc17.x86_64
But I have looked into current libvirt git and see the same code there so I don't think it is any different with current git, but I have not verified this.
Your patch applied just fine to git; I'm amending the commit message to elide this uncertainty.
The reason is systemd considers libvirt-guests.service to be stopped when the system is running:
$ systemctl status libvirt-guests.service libvirt-guests.service - Suspend Active Libvirt Guests Loaded: loaded (/usr/lib/systemd/system/libvirt-guests.service; enabled) Active: deactivating (stop) since Fri, 27 Jul 2012 15:47:31 +0200; 2min 48s ago Process: 1085 ExecStart=/etc/init.d/libvirt-guests start (code=exited, status=0/SUCCESS) Control: 1150 (libvirt-guests) CGroup: name=systemd:/system/libvirt-guests.service └ control ├ 1150 /bin/sh /etc/init.d/libvirt-guests stop └ 2257 sleep 1
libvirt-guests.service is defined as type "simple" in systemd (the default). That means systemd will shut down the service when the start executable is terminated after starting is done. Systemd will not call stop again on system shutdown because it thinks it is already stopped.
The solution is to define it as type "oneshot" and set the flag "RemainAfterExit". Then systemd will consider the service as active after startup and will call the stop function on host shutdown.
Thanks for researching this! ACK and applied. Now a followup question - in AUTHORS, you are listed as Gerd von Egidy, but in this commit, your authorship is Gerd v. Egidy. Which do you prefer, and I'll update .mailmap and possibly AUTHORS (it makes it so that 'git shortlog' will bundle all commits by you under a single listing of your preferred spelling). -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi Eric,
Thanks for researching this! ACK and applied.
Thanks.
Now a followup question - in AUTHORS, you are listed as Gerd von Egidy, but in this commit, your authorship is Gerd v. Egidy. Which do you prefer, and I'll update .mailmap and possibly AUTHORS (it makes it so that 'git shortlog' will bundle all commits by you under a single listing of your preferred spelling).
You seem to care about crediting your contributors - nice. I think I should consolidate all my email addresses an git default configs, but until that is done you can apply the attached patch. Kind regards, Gerd

On 07/30/2012 02:42 AM, Gerd v. Egidy wrote:
Hi Eric,
Thanks for researching this! ACK and applied.
Thanks.
Now a followup question - in AUTHORS, you are listed as Gerd von Egidy, but in this commit, your authorship is Gerd v. Egidy. Which do you prefer, and I'll update .mailmap and possibly AUTHORS (it makes it so that 'git shortlog' will bundle all commits by you under a single listing of your preferred spelling).
You seem to care about crediting your contributors - nice.
I personally find that showing a bit of gratitude to infrequent contributors can go a long way - open source is more than just the code, it is also the positive social aspects that it can foster :) [Then there are the legal folks that say that properly tracking contributions makes it easier to defend against litigation - but that reason for maintaining 'AUTHORS' doesn't have quite the positive connotations as a belief in a society built on decency. :) ]
I think I should consolidate all my email addresses an git default configs, but until that is done you can apply the attached patch.
Applied, and thanks again. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
Eric Blake
-
Gerd v. Egidy