commit d30dc8811fe77813394fae4183d98b0761d2be86
Author: Radek Novacek <rnovacek(a)redhat.com>
Date: Wed Dec 11 08:43:24 2013 +0100
Check if process defined by PID file exists
When virt-who is starting it now checks if the previous virt-who is
running (defined by PID file) and if not, deletes the pid file and
starts normally.
(cherry picked from commit 15abd71138e7421f7ab476027e74747e2115b9ea)
virt-who.py | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index 391207b..8cd68f6 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -300,6 +300,21 @@ def daemonize(debugMode):
os.chdir("/")
return True
+def checkPidFile():
+ try:
+ f = open(PIDFILE, "r")
+ pid = int(f.read().strip())
+ try:
+ os.kill(pid, 0)
+ print >>sys.stderr, "virt-who seems to be already running. If not,
remove %s" % PIDFILE
+ sys.exit(1)
+ except OSError:
+ # Process no longer exists
+ print >>sys.stderr, "PID file exists but associated process does
not, deleting PID file"
+ os.remove(PIDFILE)
+ except Exception:
+ pass
+
def createPidFile(logger=None):
atexit.register(cleanup)
signal.signal(signal.SIGINT, cleanup)
@@ -324,9 +339,7 @@ def cleanup(sig=None, stack=None):
sys.exit(0)
def main():
- if os.access(PIDFILE, os.F_OK):
- print >>sys.stderr, "virt-who seems to be already running. If not,
remove %s" % PIDFILE
- sys.exit(1)
+ checkPidFile()
createPidFile()
parser = OptionParserEpilog(usage="virt-who [-d] [-i INTERVAL] [-b] [-o]
[--sam|--satellite] [--libvirt|--vdsm|--esx|--rhevm|--hyperv]",
Show replies by date