Skip to contentSkip to conversation

xenstore watch for domU shutdown

DISCUSSION David Richardson 2 participants 2 messages Jan 10, 2007

lore
Share & tools
lore
#0 lore raw

Hey everyone,

I'm trying to write a simple python program in dom0 that registers a watch on the xenstore to determine when a domU has shutdown. Is there a particular token I should use? Looking through the tools/python/xen/*.py code, I've come across the 'control/shutdown' token... seems promising?

My code is attached below. As is, if fails to call the registered watch function on a domain shutdown. Any help or suggestions would be greatly appreciated. Thanks!

~Dave

#####################BEGIN CODE##############################

from xen.xend.xenstore.xsutil import *
from xen.xend.xenstore.xswatch import * from sys import argv
from xen.xend.xenstore.xstransact import xstransact

#domid of the domU guest
domid = int(argv[1])

xs = xshandle()
path = xs.get_domain_path(domid)

def myHandleShutdownWatch(_):

     f = open("/scratch/TEST", "w")
     f.write("Shutdown called")
     f.close()
     return True

mywatch = xswatch(path+"/control/shutdown",myHandleShutdownWatch)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 6 lines · David Richardson

Hey everyone,

I'm trying to write a simple python program in dom0 that registers a watch on the xenstore to determine when a domU has shutdown. Is there a particular token I should use? Looking through the tools/python/xen/*.py code, I've come across the 'control/shutdown' token... seems promising?

control/shutdown is an instruction from the tools to the domU that it should shut down. What it doesn't tell you is when a domain has gone away, because if it shuts down of its own accord or crashes, of course there won't be anything here.

The store will fire @releaseDomain whenever a domain goes away -- you then need to read from Xen to find out if its the one that you're interested in. Read through XendDomainInfo.refreshShutdown; the watch itself is registered in XendDomain.

If you're using Xend it's a little bit complicated, because Xend is going to clean up the domain under your feet, reboot it, and so on, so if you're using Xend, the easiest way would be either to modify Xend, and add a hook for what you want, or to watch @releaseDomain, read from Xen to see what has shut down, and if Xend has already cleaned up after the domain then read xend/last_shutdown_reason to find out what happened. (last_shutdown_reason appeared in very recent xen-unstable.)

Ewan.