From 51e097143c8a91f2f1a2f093db7ba8ba6dfda14d Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Fri, 4 Jul 2014 04:35:27 +0000 Subject: [PATCH] Make psutil features of our fedmsg config optional for mod_wsgi on rhel7. --- roles/fedmsg/base/templates/base.py.j2 | 22 +++++++++++++++------- roles/fedmsg/base/templates/logging.py.j2 | 14 +++++++++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/roles/fedmsg/base/templates/base.py.j2 b/roles/fedmsg/base/templates/base.py.j2 index 3eee0644ac..ab7bd9b265 100644 --- a/roles/fedmsg/base/templates/base.py.j2 +++ b/roles/fedmsg/base/templates/base.py.j2 @@ -1,9 +1,3 @@ -import os -import psutil - -pid = os.getpid() -proc = [p for p in psutil.process_iter() if p.pid == pid][0] - config = dict( # Set this to dev if you're hacking on fedmsg or an app locally. # Set to stg or prod if running in the Fedora Infrastructure. @@ -50,5 +44,19 @@ config = dict( zmq_tcp_keepalive_idle=60, zmq_tcp_keepalive_intvl=5, ) + # This option adds an IPC socket by which we can monitor hub health. -config['moksha.monitoring.socket'] = 'ipc:///var/run/fedmsg/monitoring-%s.socket' % proc.name +try: + import os + import psutil + + pid = os.getpid() + proc = [p for p in psutil.process_iter() if p.pid == pid][0] + + config['moksha.monitoring.socket'] = \ + 'ipc:///var/run/fedmsg/monitoring-%s.socket' % proc.name +except OSError: + # We run into issues when trying to import psutil from mod_wsgi on rhel7 + # but this feature is of no concern in that context, so just fail quietly. + # https://github.com/jmflinuxtx/kerneltest-harness/pull/17#issuecomment-48007837 + pass diff --git a/roles/fedmsg/base/templates/logging.py.j2 b/roles/fedmsg/base/templates/logging.py.j2 index de0fe02f42..5cc65aa6b2 100644 --- a/roles/fedmsg/base/templates/logging.py.j2 +++ b/roles/fedmsg/base/templates/logging.py.j2 @@ -4,10 +4,18 @@ import inspect import logging import os -import psutil import socket import traceback +psutil = None +try: + import psutil +except OSError: + # We run into issues when trying to import psutil from inside mod_wsgi on + # rhel7. If we hit that here, then just fail quietly. + # https://github.com/jmflinuxtx/kerneltest-harness/pull/17#issuecomment-48007837 + pass + class ContextInjector(logging.Filter): """ Logging filter that adds context to log records. @@ -57,6 +65,10 @@ class ContextInjector(logging.Filter): @staticmethod def get_current_process(): mypid = os.getpid() + + if not psutil: + raise OSError("Could not import psutil for %r" % mypid) + for proc in psutil.process_iter(): if proc.pid == mypid: return proc