Skip to content

Commit 9d24e44

Browse files
Set environment variables indicating that mod_wsgi-express is being used and what debug modes.
1 parent 44b3db0 commit 9d24e44

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

docs/release-notes/version-4.4.11.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,29 @@ specifying the name of a log file for a specific service script. The
3333
arguments are the name of the service and the file name for the log. The
3434
log file will be placed in the log directory, be it the default, or a
3535
specific log directory if specified.
36+
37+
2. Set various environment variables from ``mod_wsgi-express`` to identify
38+
that it is being used, what hosts it is handling requests for, and whether
39+
debug mode and/or specific debug mode features are enabled. This is so that
40+
a web application can modify it's behaviour when ``mod_wsgi-express`` is
41+
being used, or being used in specific ways. The environment variables which
42+
are set are:
43+
44+
* *MOD_WSGI_EXPRESS* - Indicates that ``mod_wsgi-express`` is being used.
45+
* *MOD_WSGI_SERVER_NAME* - The primary server host name for the site.
46+
* *MOD_WSGI_SERVER_ALIASES* - Secondary host names the site is known by.
47+
* *MOD_WSGI_RELOADER_ENABLED* - Indicates if source code reloading enabled.
48+
* *MOD_WSGI_DEBUG_MODE* - Indicates if debug mode has been enabled.
49+
* *MOD_WSGI_DEBUGGER_ENABLED* - Indicates pdb debugger has been enabled.
50+
* *MOD_WSGI_COVERAGE_ENABLED* - Indicates if coverage analysis has been
51+
enabled.
52+
* *MOD_WSGI_PROFILER_ENABLED* - Indicates if code profiling has been enabled.
53+
* *MOD_WSGI_RECORDER_ENABLED* - Indicates if request/response recording
54+
enabled.
55+
* *MOD_WSGI_GDB_ENABLED* - Indicates if gdb process crash debugging enabled.
56+
57+
For any environment variable indicating a feature has been enabled, it
58+
will be set when enabled and have the value 'true'.
59+
60+
For the list of server aliases, it will be a space separated list of host
61+
names.

src/server/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,8 +1370,18 @@ def __call__(self, environ, start_response):
13701370
profiler_directory = '%(profiler_directory)s'
13711371
enable_recorder = %(enable_recorder)s
13721372
recorder_directory = '%(recorder_directory)s'
1373+
enable_gdb = %(enable_gdb)s
1374+
1375+
os.environ['MOD_WSGI_EXPRESS'] = 'true'
1376+
os.environ['MOD_WSGI_SERVER_NAME'] = '%(server_host)s'
1377+
os.environ['MOD_WSGI_SERVER_ALIASES'] = %(server_aliases)r or ''
1378+
1379+
if reload_on_changes:
1380+
os.environ['MOD_WSGI_RELOADER_ENABLED'] = 'true'
13731381
13741382
if debug_mode:
1383+
os.environ['MOD_WSGI_DEBUG_MODE'] = 'true'
1384+
13751385
# We need to fiddle sys.path as we are not using daemon mode and so
13761386
# the working directory will not be added to sys.path by virtue of
13771387
# 'home' option to WSGIDaemonProcess directive. We could use the
@@ -1380,11 +1390,16 @@ def __call__(self, environ, start_response):
13801390
13811391
sys.path.insert(0, working_directory)
13821392
1393+
if enable_debugger:
1394+
os.environ['MOD_WSGI_DEBUGGER_ENABLED'] = 'true'
1395+
13831396
def output_coverage_report():
13841397
coverage_info.stop()
13851398
coverage_info.html_report(directory=coverage_directory)
13861399
13871400
if enable_coverage:
1401+
os.environ['MOD_WSGI_COVERAGE_ENABLED'] = 'true'
1402+
13881403
from coverage import coverage
13891404
coverage_info = coverage()
13901405
coverage_info.start()
@@ -1397,11 +1412,19 @@ def output_profiler_data():
13971412
profiler_info.dump_stats(output_file)
13981413
13991414
if enable_profiler:
1415+
os.environ['MOD_WSGI_PROFILER_ENABLED'] = 'true'
1416+
14001417
from cProfile import Profile
14011418
profiler_info = Profile()
14021419
profiler_info.enable()
14031420
atexit.register(output_profiler_data)
14041421
1422+
if enable_recorder:
1423+
os.environ['MOD_WSGI_RECORDER_ENABLED'] = 'true'
1424+
1425+
if enable_gdb:
1426+
os.environ['MOD_WSGI_GDB_ENABLED'] = 'true'
1427+
14051428
if with_newrelic_agent:
14061429
if newrelic_config_file:
14071430
os.environ['NEW_RELIC_CONFIG_FILE'] = newrelic_config_file
@@ -2714,6 +2737,8 @@ def _cmd_setup_server(command, args, options):
27142737
else:
27152738
host = options['host']
27162739

2740+
options['server_host'] = host
2741+
27172742
if options['port'] == 80:
27182743
options['url'] = 'http://%s/' % host
27192744
else:

0 commit comments

Comments
 (0)