Lets solve your Django logging issue and put aside the issue of moving to 
mod_wsgi-express for now.

For a process other that PID 1 to log director the container stdout/stderr, it 
can use:

    /proc/1/fd/1
    /proc/1/fd/2

Your Django logging configuration, to have it avoid the Apache error logging 
mechanism would thus be something like:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'file': {
            'class': 'logging.FileHandler',
            'filename': '/proc/1/fd/1',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['file'],
            'level': 'INFO',
        },
    },
}

So get that working with your existing images. We can then see later whether is 
worthwhile looking at mod_wsgi-express.

What you might at least get out of mod_wsgi-express is some hints as to 
possible better configuration for working in a container. This is because 
mod_wsgi-express generates a complete Apache configuration for you. You don't 
just point it at the existing Apache configuration directories/server root as 
you are. You then just add snippets for additional configuration not handled by 
mod_wsgi-express. Setting up mod_kerb may be a bit fiddly to add as an extra, 
thus why keeping what you are doing for now and just configuring Django logging 
may well be better approach.

> On 17 Dec 2018, at 1:20 pm, [email protected] wrote:
> 
> Hi folks,
> 
> TL;DR my app doesn't work because "Embedded mode of mod_wsgi disabled by 
> runtime configuration" and I don't know why...
> 
> -- Background
>  
> I've got an apache2/mod_wsgi docker environment set up for multiple (30-ish) 
> microservices to migrate to, but we've hit a major sticking point: these 
> docker containers all run in kubernetes, and have these requirements:
> 
> - the service must run as PID 1, and
> - all logging must go to stdout/stderr
> - all logging must be in JSON format for ingest by ELK
> 
> I've configured apache to sent ErrorLog and AccessLog to stdout, no problems. 
> I've also configured them to log JSON (not pretty, but it works). The 
> application (Django) is also configured to log JSON, and that's where the 
> problem comes in: apache captures *all* output from the Django app and 
> formats it into the ErrorLog, producing invalid JSON.
> 
> I can't seem to get Django to circumvent apache's output capture. Getting 
> Django to log directly to /dev/stdout doesn't work.
> 
> Graham suggested on twitter I should use mod_wsgi-express to solve my logging 
> problems, so the below is my current state of trying to get it working.
> 
> Our apache configuration is not trivial (amongst other things it includes 
> mod_kerb). I've developed the docker image using Debian slim (based off 
> existing work folks here have done with mod_kerb and other components) and 
> have followed the standard Debian apache configuration patterns. Through 
> benchmarking and load testing we've configured our servers and threads to 
> suit a particular memory usage model. So switching to mod_wsgi-express has 
> been ... challenging. I'm struggling to find documentation for 
> mod_wsgi-express - the PyPI page says docs are at www.modwsgi.org but that 
> says the docs are on PyPI. The `start-server --help` is helping though I'm 
> not entirely sure what the difference between setup-server and start-server 
> is (or if I even should care).
> 
> -- Where I'm stuck
> 
> So far I've got this command line:
> 
>     mod_wsgi-express start-server --include-file /etc/apache2/apache2.conf 
> --server-root /etc/apache2 /app/main/wsgi.py
> 
> My configuration is used \o/ though we configure StartServers and 
> ThreadsPerChild but those seem to be trumped by the --processes and --threads 
> command line options. Is there something I've missed here?
> 
> That niggle aside, the application doesn't run. I get "Embedded mode of 
> mod_wsgi disabled by runtime configuration: /app/main/wsgi.py" I think it's 
> related to mod_wsgi "daemon" mode, but I can't see any mod_wsgi-express 
> option related to that. My wsgi.py is very simple:
> 
> from django.core.wsgi import get_wsgi_application
> 
> def application(env, start_response):
>     return get_wsgi_application()(env, start_response)
> 
> My mod_wsgi-related apache configuration is:
> 
> WSGIScriptAlias / /app/main/wsgi.py
> WSGIPythonHome /venv
> WSGIPythonPath /app
> 
> So I'm not sure where to go from here...
> 
> 
> Thanks,
> 
>      Richard
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at https://groups.google.com/group/modwsgi 
> <https://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to