Module: check_mk
Branch: master
Commit: 3d5fe7b636ea689c1742b5e5bcd5da854d8c8666
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3d5fe7b636ea68…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Dec 12 12:54:05 2017 +0100
5578 FIX Fixed process locking (pid file handling)
The PID file handling of the Event Console had the following issues:
a) The locking was only done by the init script. Manual executions
could lead to multiple running EC processes. This has been fixed
by adding an additional file lock to the PID file.
b) The PID file was only removed in case the EC stopped without
exception. In case one happened, the PID file was left over
refering to the old PID.
Change-Id: I5714a45a039dbfd7a1486733121cf2b44f5fb91c
---
.werks/5578 | 17 +++++++++++++++++
bin/mkeventd | 11 ++++++++---
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/.werks/5578 b/.werks/5578
new file mode 100644
index 0000000..8bbb965
--- /dev/null
+++ b/.werks/5578
@@ -0,0 +1,17 @@
+Title: Fixed process locking (pid file handling)
+Level: 1
+Component: ec
+Compatible: compat
+Edition: cre
+Version: 1.5.0i2
+Date: 1513079448
+Class: fix
+
+The PID file handling of the Event Console had the following issues:
+
+ a) The locking was only done by the init script. Manual executions
+ could lead to multiple running EC processes. This has been fixed
+ by adding an additional file lock to the PID file.
+ b) The PID file was only removed in case the EC stopped without
+ exception. In case one happened, the PID file was left over
+ refering to the old PID.
diff --git a/bin/mkeventd b/bin/mkeventd
index e8642a9..866ed04 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -5144,8 +5144,7 @@ if __name__ == "__main__":
cmk.daemon.daemonize()
logger.info("Daemonized with PID %d." % os.getpid())
- # Create PID file
- file(g_pid_file, "w").write("%d\n" % os.getpid())
+ cmk.daemon.lock_with_pid_file(g_pid_file)
# Install signal hander
signal.signal(signal.SIGHUP, signal_handler)
@@ -5189,10 +5188,16 @@ if __name__ == "__main__":
pass
logger.info("Successfully shut down.")
- os.remove(g_pid_file)
sys.exit(0)
except:
if opt_debug:
raise
bail_out(traceback.format_exc())
+
+ finally:
+ if cmk.store.have_lock(g_pid_file):
+ try:
+ os.remove(g_pid_file)
+ except OSError:
+ pass