From 8f2c1ce9e917e81c34c2e784bf318e09057b88b3 Mon Sep 17 00:00:00 2001 From: James Bulpin Date: Fri, 24 Jan 2014 15:52:59 +0000 Subject: [PATCH] IsXAPIRunning check for /run/pid and /var/run/pid based identification of running xapi --- XSConsoleData.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/XSConsoleData.py b/XSConsoleData.py index fe043d3..28394af 100644 --- a/XSConsoleData.py +++ b/XSConsoleData.py @@ -15,7 +15,7 @@ import XenAPI -import commands, re, shutil, sys, tempfile, socket +import commands, re, shutil, sys, tempfile, socket, os from pprint import pprint from simpleconfig import SimpleConfigFile @@ -1051,10 +1051,28 @@ def PurgeVBDs(self): def IsXAPIRunning(self): try: - if ShellPipe('/sbin/pidof', '-s', '/opt/xensource/bin/xapi').CallRC() == 0: - retVal = True + pidfile = None + if os.path.exists("/run/xapi.pid"): + pidfile = "/run/xapi.pid" + elif os.path.exists("/var/run/xapi.pid"): + pidfile = "/var/run/xapi.pid" + if pidfile: + # Look for any "xapi" running + pid = file(pidfile).read().strip() + exelink = "/proc/%s/exe" % (pid) + if os.path.exists(exelink): + if os.path.basename(os.readlink(exelink)) == "xapi": + retVal = True + else: + retVal = False + else: + retVal = False else: - retVal = False + # Look for XenServer/XCP appliance xapi + if ShellPipe('/sbin/pidof', '-s', '/opt/xensource/bin/xapi').CallRC() == 0: + retVal = True + else: + retVal = False except: retVal = False return retVal