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

Gerd v. Egidy lists at egidy.de
Fri Jul 27 15:01:04 UTC 2012


I originally postet this into the Fedora bugzilla
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:

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; 
          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,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvirt-guests-systemd-oneshot.patch
Type: text/x-patch
Size: 491 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120727/c21b6102/attachment-0001.bin>

More information about the libvir-list mailing list