18

We have a CentOS 5.5 KVM host, running guests with various versions of CentOS and possibly other OSes later.

We'd like to be able to either (a) automatically send an ACPI shutdown to all guests or (b) suspend all guests to disk, on host shutdown.

Is there a standard method to accomplish either of these, or is it a roll-your-own situation? Thanks!

Andrew Clegg
  • 377
  • 1
  • 2
  • 9

4 Answers4

6

Yes.

The virsh shutdown command (or other implementations of "shutdown" using libvirt, as in virt-manager) instructs the guest OS to shut down cleanly. From the man page:

   shutdown domain-id

   Gracefully shuts down a domain.  This coordinates with the domain
   OS to perform graceful shutdown, so there is no guarantee that it
   will succeed, and may take a variable length of time depending on
   what services must be shutdown in the domain.

   The exact behavior of a domain when it shuts down is set by the
   on_shutdown parameter in the domain’s XML definition.

With KVM, this should send an ACPI system_powerdown event.

In Fedora and RHEL 6, a libvirt-guests init script comes out of the box configured to suspend all guests on system shutdown. It's not particularly magic, though, so one could copy this to CentOS 5 with little modification.

mattdm
  • 6,550
  • 1
  • 25
  • 48
  • That's a good idea, I have a Fedora machine, I'll have a go at backporting it to CentOS5. Thanks. – Andrew Clegg Dec 09 '10 at 11:56
  • I can't see on_shutdown in the doco: http://libvirt.org/formatdomain.html#elementsLifecycle – Thiago Figueiro Sep 26 '11 at 22:55
  • Hmmmm. Yeah, it's also suspiciously [missing in the code](http://libvirt.org/git/?p=libvirt.git&a=search&h=HEAD&st=grep&s=on_shutdown). What the `libvirt-guests` script _actually_ does is run `virsh managedsave`. (It looks like maybe only the UML driver supports system_powerdown.) Thanks for the catch! I'll update my answer, and file a bug against the documentation. – mattdm Sep 26 '11 at 23:48
4

This is now a standard feature in recent Fedora and RHEL 6.

0

As far as I know there is no such standard script for CentOS. It is possible to code up, but a little dangerous, as you need to handle guests that take a long time to shut down. Just killing them after a time-out can destroy data, while waiting for them can leave your shutdown hanging.

Instead it's better to shut down guests by hand before doing a reboot. For a while I had a script that replaced shutdown and reboot. That script warned me if there was any running guests (simple lc on the list of virtual machines) and blocked the command if there was running guests.

pehrs
  • 8,749
  • 29
  • 46
-3

KVM guests are just userspace processes. you should have some process monitoring in place. the most common out there seems to be libvirt (it's developed by RedHat, so i guess it should be available on CentOS).

Javier
  • 9,078
  • 2
  • 23
  • 24
  • When process is killed, the shutdown is rather a power off. I think we must a gracefull shutdown. In addition, why not to use the libvirt interface (`virsh`) – MUY Belgium Oct 22 '20 at 09:43