Module: check_mk
Branch: master
Commit: 88d580b7f1b92053631069c623d43e98e731f04b
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=88d580b7f1b920…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Fri Jan 28 10:18:32 2011 +0100
Fix bug 109: Nagios does not any longer inherit FDs from Apache
So a restart of Apache after a WATO reload is possible again
in OMD.
---
.bugs/109 | 11 ++++++++---
modules/check_mk.py | 17 ++++++++++++++++-
2 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/.bugs/109 b/.bugs/109
index 3540e9b..47e3e8d 100644
--- a/.bugs/109
+++ b/.bugs/109
@@ -1,10 +1,11 @@
Title: Restart of Nagios makes Nagios inherit TCP port
Component: wato
+State: done
+Class: bug
+Date: 2011-01-26 09:12:21
Benefit: 4
-State: open
Cost: 2
-Date: 2011-01-26 09:12:21
-Class: bug
+Fun: 0
If you restart Nagios via WATO, then Apache restarts Nagios
und the new Nagios process inherits the open files of Apache.
@@ -14,3 +15,7 @@ makes it impossible to restart apache later.
Solution unclear. Either user reload instead of restart or
try to explicitely close all filedescriptors after forking.
But how can we do that?
+
+2011-01-28 10:18:26: changed state open -> done
+Fixed in modules/check_mk.py. We close all filedescriptors from 3..256 before
+restarting Nagios.
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 755bc6e..208307b 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -3654,8 +3654,23 @@ def automation_delete_host(args):
os.system("rm -rf '%s'" % path)
def automation_restart():
+ # make sure, Nagios does not inherit any open
+ # filedescriptors. This really happens, e.g. if
+ # check_mk is called by WATO via Apache. Nagios inherits
+ # the open file where Apache is listening for incoming
+ # HTTP connections. Really.
+ os.closerange(3, 256)
+
+ class fake_file():
+ def write(self, stuff):
+ pass
+ def flush(self):
+ pass
+
+ # Deactivate stdout by introducing fake file without filedescriptor
old_stdout = sys.stdout
- sys.stdout = file('/dev/null', 'w')
+ sys.stdout = fake_file()
+
try:
if os.path.exists(nagios_objects_file):
backup_path = nagios_objects_file + ".save"