From 2931346c5e9e4250e5637e8bed759bf5067fd7ba Mon Sep 17 00:00:00 2001
From: Tim Abbott <tabbott@humbughq.com>
Date: Thu, 25 Oct 2012 17:40:30 -0400
Subject: [PATCH] Kill duplicate zephyr mirror processes on startup.
(imported from commit 52db0c911e5d60a54eb43c5c075709c02e75da63)
---
bots/zephyr_mirror.py | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/bots/zephyr_mirror.py b/bots/zephyr_mirror.py
index 44e671eb..bc02d232 100755
--- a/bots/zephyr_mirror.py
+++ b/bots/zephyr_mirror.py
@@ -440,6 +440,18 @@ if options.forward_from_humbug:
print "This option is obsolete."
sys.exit(0)
+# First check that there are no other bots running
+cmdline = " ".join(sys.argv)
+proc = subprocess.Popen(['pgrep', '-U', os.environ["USER"], "-f", cmdline],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+out, _err_unused = proc.communicate()
+for pid in out.split():
+ if int(pid.strip()) != os.getpid():
+ # Another copy of zephyr_mirror.py! Kill it.
+ print "Killing duplicate zephyr_mirror process %s" % pid
+ os.kill(int(pid), signal.SIGKILL)
+
child_pid = os.fork()
if child_pid == 0:
# Run the humbug => zephyr mirror in the child