commit 15abd71138e7421f7ab476027e74747e2115b9ea
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.
virt-who.py | 19 ++++++++++++++++---
1 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/virt-who.py b/virt-who.py
index 52ec318..32e3c05 100644
--- a/virt-who.py
+++ b/virt-who.py
@@ -289,6 +289,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)
@@ -313,9 +328,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(description="Agent for reporting virtual guest IDs
to subscription-manager",
Show replies by date