Script: Shutting Down All Xen VMs on a Server
Posted on In VirtualizationShutting 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:
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!
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.
Oh, I didn’t know this…
Thanks for the tip. I have updated the post.