Script: Shutting Down All Xen VMs on a Server

Shutting down servers is a common operations for managing a cluster. However, if this server is configured to a Xen Dom0 and has Xen VMs (DomUs), the VMs should be shutdown first to avoid data lost on these VMs.

xm supports a -a option to shutdown all VMs:

# xm shutdown -a

Add the -w if you want to make it wait for the domain to complete shutdown before returning

Thanks to Eugene for this tips. The script below is a “poor man”‘s solution.


I wrote a Bash script to automatically list all running VMs and shutdown them down by calling xm which I use to shutdown VMs on servers before turning them off.

The xen-shutdown-all.sh script is on github:

xen-shutdown-all.sh.

This script use the xm command for management. If you are using a newer version of Xen which possibly uses xl for VM management, you can easily change the script by replacing xm with xl and make other possibly required changes.

Enjoy!

Eric Zhiqiang Ma

Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

2 comments:

  1. why?

    xm shutdown -a

    shutdown [OPTIONS] domain-id

    OPTIONS

    -a Shutdown all domains. Often used when doing a complete shutdown of a Xen system.

    -w Wait for the domain to complete shutdown before returning.

Leave a Reply

Your email address will not be published. Required fields are marked *