Module: check_mk
Branch: master
Commit: 97ac39ba934a87457a82a79fb26992705d3e85a6
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=97ac39ba934a87…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Feb 27 09:43:51 2018 +0100
5870 FIX Removed PYTHONPATH from site environment
The PYTHONPATH environment variable which was set by omd and .profile for all processes
in the site was confusing external Python based tools like for example gdb or the command
not found helpers of Ubuntu. This resulted in confusing stack traces.
The PYTHONPATH needed to be set in previous versions to make the python environment know
about the site specific python module paths (lib/python, local/lib/python). These paths
are now set using standard mechanisms of python (lib/python2.7/sitecustomize.py).
Change-Id: Ia9fefa38efa8f9e3bac0e51b5253defb754463a8
---
.werks/5870 | 16 ++++++++++++
omd/packages/maintenance/merge-crontabs | 1 -
omd/packages/mod_python/.f12 | 3 +--
omd/packages/mod_python/Makefile | 1 -
.../patches/0004-omd-add-python-path.dif | 30 ----------------------
omd/packages/omd/omd | 1 -
omd/packages/omd/skel/.profile | 1 -
omd/packages/python/Makefile | 1 +
omd/packages/python/sitecustomize.py | 18 +++++++++++++
9 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/.werks/5870 b/.werks/5870
new file mode 100644
index 0000000..e75c6a1
--- /dev/null
+++ b/.werks/5870
@@ -0,0 +1,16 @@
+Title: Removed PYTHONPATH from site environment
+Level: 1
+Component: omd
+Compatible: compat
+Edition: cre
+Version: 1.5.0i4
+Date: 1519720796
+Class: fix
+
+The PYTHONPATH environment variable which was set by omd and .profile for all processes
+in the site was confusing external Python based tools like for example gdb or the
command
+not found helpers of Ubuntu. This resulted in confusing stack traces.
+
+The PYTHONPATH needed to be set in previous versions to make the python environment know
+about the site specific python module paths (lib/python, local/lib/python). These paths
+are now set using standard mechanisms of python (lib/python2.7/sitecustomize.py).
diff --git a/omd/packages/maintenance/merge-crontabs
b/omd/packages/maintenance/merge-crontabs
index 4e5f463..e176cbe 100755
--- a/omd/packages/maintenance/merge-crontabs
+++ b/omd/packages/maintenance/merge-crontabs
@@ -23,7 +23,6 @@ BASH_ENV=%(omd_root)s/.profile
sys.stdout.write("OMD_ROOT=%s\n" % os.environ['OMD_ROOT'])
sys.stdout.write("OMD_SITE=%s\n" % os.environ['OMD_SITE'])
sys.stdout.write("PATH=%s\n" % os.environ['PATH'])
-sys.stdout.write("PYTHONPATH=%s\n" % os.environ['PYTHONPATH'])
sys.stdout.write("MAILTO=\"%s\"\n" %
omd_config.get('CONFIG_ADMIN_MAIL', ''))
sys.stdout.write("#
------------------------------------------------------------\n")
diff --git a/omd/packages/mod_python/.f12 b/omd/packages/mod_python/.f12
index 3104327..a9216ef 100755
--- a/omd/packages/mod_python/.f12
+++ b/omd/packages/mod_python/.f12
@@ -5,7 +5,6 @@ SITE=${SITE:-$(cat ../../../.site 2>/dev/null || true)}
SITE=${SITE:-$(omd sites --bare | head -n 1)}
ROOT=/omd/sites/$SITE
-echo '#define OMD_VERSION "$(omd versions | grep default | cut -d' '
-f1)"' > mod_python-*/src/omd_version.h
-make -C mod_python-* clean all
+make -C mod_python-3.3.1 clean all
sudo make install OMD_ROOT=$ROOT
sudo omd restart $SITE apache
diff --git a/omd/packages/mod_python/Makefile b/omd/packages/mod_python/Makefile
index b54a2fa..4e8fd74 100644
--- a/omd/packages/mod_python/Makefile
+++ b/omd/packages/mod_python/Makefile
@@ -31,7 +31,6 @@ build: check-python
export LD_LIBRARY_PATH="$(PACKAGE_PYTHON_LD_LIBRARY_PATH)" ; \
cd $(DIR) ; \
./configure $(CONFIGUREOPTS) ; \
- echo '#define OMD_VERSION "$(OMD_VERSION)"' > src/omd_version.h ;
\
$(MAKE) all
install:
diff --git a/omd/packages/mod_python/patches/0004-omd-add-python-path.dif
b/omd/packages/mod_python/patches/0004-omd-add-python-path.dif
deleted file mode 100644
index 4f34132..0000000
--- a/omd/packages/mod_python/patches/0004-omd-add-python-path.dif
+++ /dev/null
@@ -1,30 +0,0 @@
---- mod_python-3.3.1/src/mod_python.c.orig 2006-11-09 07:21:23.000000000 +0100
-+++ mod_python-3.3.1/src/mod_python.c 2013-01-16 14:08:54.453232213 +0100
-@@ -26,6 +26,7 @@
- */
-
- #include "mod_python.h"
-+#include "omd_version.h"
-
- /* Server object for main server as supplied to python_init(). */
- static server_rec *main_server = NULL;
-@@ -103,6 +104,19 @@
- * >>> <initstring>
- * in the __main__ module to start up Python.
- */
-+
-+ /*
-+ * This has to be called before PyImport_ImportModule(MODULENAME) because
-+ * this extends the python path with the path to the OMD related mod_python
-+ * module. Without this patch there might occur several problem related to
-+ * duplicate imports of modules where some modules are located in the local/
-+ * hiearchy in OMD.
-+ *
-+ * FYI: MODULENAME is "mod_python.apache".
-+ */
-+ PyObject *sysPath = PySys_GetObject("path");
-+ PyObject *path = PyString_FromString("/omd/versions/" OMD_VERSION
"/lib/python");
-+ int result = PyList_Insert(sysPath, 0, path);
-
- if (! ((m = PyImport_ImportModule(MODULENAME)))) {
- PyObject *path;
diff --git a/omd/packages/omd/omd b/omd/packages/omd/omd
index 8d9c7d3..4267038 100644
--- a/omd/packages/omd/omd
+++ b/omd/packages/omd/omd
@@ -2319,7 +2319,6 @@ def set_environment():
putenv("LD_LIBRARY_PATH", "%s/local/lib:%s/lib" % (g_sitedir,
g_sitedir))
putenv("HOME", g_sitedir)
- putenv("PYTHONPATH", "%s/local/lib/python:%s/lib/python" %
(g_sitedir, g_sitedir))
# allow user to define further environment variable in ~/etc/environment
envfile = g_sitedir + "/etc/environment"
diff --git a/omd/packages/omd/skel/.profile b/omd/packages/omd/skel/.profile
index 7ee3d55..86d8a2c 100644
--- a/omd/packages/omd/skel/.profile
+++ b/omd/packages/omd/skel/.profile
@@ -11,7 +11,6 @@ export PATH="$OMD_ROOT/lib/perl5/bin:$PATH"
export MODULEBUILDRC="$OMD_ROOT/.modulebuildrc"
export PERL_MM_OPT=INSTALL_BASE="$OMD_ROOT/local/lib/perl5/"
export MANPATH="$OMD_ROOT/share/man:$MANPATH"
-export PYTHONPATH="$OMD_ROOT/local/lib/python:$OMD_ROOT/lib/python"
export MAILRC="$OMD_ROOT/etc/mail.rc"
# Make the python requests module trust the CAs configured in Check_MK
diff --git a/omd/packages/python/Makefile b/omd/packages/python/Makefile
index 872f851..fcbba64 100644
--- a/omd/packages/python/Makefile
+++ b/omd/packages/python/Makefile
@@ -81,6 +81,7 @@ install: bin/gcc bin/g++
$(DESTDIR)$(OMD_ROOT)/bin/pydoc \
$(DESTDIR)$(OMD_ROOT)/bin/python2.7-config \
$(DESTDIR)$(OMD_ROOT)/bin/2to3
+ install -m 644 sitecustomize.py $(DESTDIR)$(OMD_ROOT)/lib/python2.7/
skel:
diff --git a/omd/packages/python/sitecustomize.py b/omd/packages/python/sitecustomize.py
new file mode 100644
index 0000000..6a6e6d6
--- /dev/null
+++ b/omd/packages/python/sitecustomize.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+# Make the site python know about the Check_MK specific python module paths
+
+import sys, os
+
+# Set the Check_MK version specific python module directory. This is
+# the location for the extra python modules shipped with Check_MK.
+version_path = os.path.dirname(os.path.dirname(sys.executable))
+sys.path.insert(0, version_path + "/lib/python")
+
+# Regular use case: When "omd" is being executed as root, we don't know
+# anything about the site -> Only set the version specific directory.
+omd_root = os.environ.get("OMD_ROOT")
+if omd_root:
+ # Set the site local python module directory. This is the place
+ # for extension modules of the user, for example installed manually
+ # or via pip.
+ sys.path.insert(0, omd_root + "/local/lib/python")