From dc84b8d53b272adaca6c54f413b3b87cdbcc7f66 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Fri, 5 Feb 2016 13:25:47 -0800 Subject: [PATCH] Manually set our $PATH before executing uwsgi bin This fixes cases when spawning `sentry` bin without activating our virtualenv. We derive the $PATH based on where `sentry` was run from, and `uwsgi` should be sitting next to it. Fixes GH-2649 --- src/sentry/services/http.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/sentry/services/http.py b/src/sentry/services/http.py index 3872ec3c1ff6df..50993d95dae1d8 100644 --- a/src/sentry/services/http.py +++ b/src/sentry/services/http.py @@ -124,4 +124,14 @@ def run(self): # This has already been validated inside __init__ os.environ['SENTRY_SKIP_BACKEND_VALIDATION'] = '1' + # Look up the bin directory where `sentry` exists, which should be + # sys.argv[0], then inject that to the front of our PATH so we can reliably + # find the `uwsgi` that's installed when inside virtualenv. + # This is so the virtualenv doesn't need to be sourced in, which effectively + # does exactly this. + virtualenv_path = os.path.dirname(os.path.abspath(sys.argv[0])) + current_path = os.environ.get('PATH', '') + if virtualenv_path not in current_path: + os.environ['PATH'] = '%s:%s' % (virtualenv_path, current_path) + os.execvp('uwsgi', ('uwsgi',))