Prerequisites

  • XCP/Xenserver

 

Sometimes I get a stuck Virtual Machine that just won't go down and it's usually due to a lack of memory in the VM. When I issue a shutdown command from within the VM it starts the shutdown process but hangs part way through. Executing xe vm-shutdown --force uuid=<insert UUID here>  does nothing but lock up the terminal. If this happens to you follow the steps below to forcefully shut the VM down.  

  1. xe task-list (find the pending tasks UUID)
  2. xe task-cancel uuid=<task UUID>
  3. xe vm-list (note the VM's UUID)
  4. list_domains (find the VM's UUID and note the domain id)
  5. /opt/xensource/debug/destroy_domain -domid XX (where XX is the domain id from step 2)
  6. xe vm-shutdown --force uuid=<UUID from step 1>
This will canceling the tasks that may be locking any new tasks e.g. the shutdown commands, destroying the domain and then shutting the VM down. I've had to do this several times on an Apache webserver that's getting pummeled from the Internet. 
 

The steps above in script form (if you trust me). Step one has to be entered in manually. The rest can be copied and pasted.

name="Name Label"
TASK=$(xe task-list status=pending --minimal)
xe task-cancel uuid="$TASK"
VMUUID=$(xe vm-list name-label="$name" --minimal)
DOMID=$(xe vm-list uuid="$VMUUID" params=dom-id --minimal) /opt/xensource/debug/destroy_domain -domid "$DOMID" xe vm-shutdown --force uuid="$VMUUID"