Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question

4 Answers 4

up vote 2 down vote accepted

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.

share|improve this answer
    
That's a good idea, I have a Fedora machine, I'll have a go at backporting it to CentOS5. Thanks. –  Andrew Clegg Dec 9 '10 at 11:56
    
I can't see on_shutdown in the doco: libvirt.org/formatdomain.html#elementsLifecycle –  XCondE Sep 26 '11 at 22:55
    
Hmmmm. Yeah, it's also suspiciously missing in the code. 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

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

share|improve this answer
    
I think it was addressed in Ubuntu as well: bugs.launchpad.net/ubuntu/+source/libvirt/+bug/350936 –  hdave Mar 14 '13 at 14:32

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).

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.