19

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!

4 Answers 4

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.

3
  • That's a good idea, I have a Fedora machine, I'll have a go at backporting it to CentOS5. Thanks. Dec 9, 2010 at 11:56
  • I can't see on_shutdown in the doco: libvirt.org/formatdomain.html#elementsLifecycle Sep 26, 2011 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, 2011 at 23:48
4

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

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

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

1
  • 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) Oct 22, 2020 at 9:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .