Reputation: 733
I need to set: WSGIRestrictSignal Off because I have to perform some things in my python code once the graceful shutdown is invoked.
From documentation:
A well behaved Python WSGI application should not in general register any signal handlers of its own using signal.signal(). The reason for this is that the web server which is hosting a WSGI application will more than likely register signal handlers of its own. If a WSGI application were to override such signal handlers it could interfere with the operation of the web server, preventing actions such as server shutdown and restart.
Do you know how change configuration file in Docker?
Shall I just overwrite the existing file?
this is my Dockerfile:
FROM grahamdumpleton/mod-wsgi-docker:python-2.7
ADD requirements.txt requirements.txt
RUN ["pip", "install", "-r", "requirements.txt"]
WORKDIR /app
COPY src/main/scripts/app.wsgi /app/app.wsgi
ENTRYPOINT [ "mod_wsgi-docker-start" ]
CMD [ "app.wsgi", "--processes", "1", "--port", "5000" ]
shall I put something like this?
ADD "httpd.conf" /tmp/mod_wsgi-localhost:5000:0/httpd.conf
As far as I got the mod_wsgi-docker-start" is executing everything by choosing "default" configuration.
Due the fact that the WSGIRestrictSignal is set to On "Default" it is impossible to capture signal if it is raised:
Server URL : http://localhost:5000/
Server Root : /tmp/mod_wsgi-localhost:5000:0
Server Conf : /tmp/mod_wsgi-localhost:5000:0/httpd.conf
Error Log File : /dev/stderr (warn)
Startup Log File : /dev/stderr
Request Capacity : 5 (1 process * 5 threads)
Request Timeout : 60 (seconds)
Startup Timeout : 15 (seconds)
Queue Backlog : 100 (connections)
Queue Timeout : 45 (seconds)
Server Capacity : 20 (event/worker), 20 (prefork)
Server Backlog : 500 (connections)
Locale Setting : en_US.UTF-8
[Wed Sep 06 09:37:32.673894 2017] [mpm_event:notice] [pid 14:tid 140686654945024] AH00489: Apache/2.4.25 (Unix) mod_wsgi/4.5.7 Python/2.7 configured -- resuming normal operations
[Wed Sep 06 09:37:32.674133 2017] [core:notice] [pid 14:tid 140686654945024] AH00094: Command line: 'httpd (mod_wsgi-express) -f /tmp/mod_wsgi-localhost:5000:0/httpd.conf -E /dev/stderr -D MOD_WSGI_MULTIPROCESS -D MOD_WSGI_MPM_ENABLE_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_EVENT_MODULE -D MOD_WSGI_MPM_EXISTS_WORKER_MODULE -D MOD_WSGI_MPM_EXISTS_PREFORK_MODULE -D FOREGROUND'
^C[Wed Sep 06 09:37:33.106471 2017] [mpm_event:notice] [pid 14:tid 140686654945024] AH00491: caught SIGTERM, shutting down
[Wed Sep 06 09:37:33.254507 2017] [wsgi:warn] [pid 16:tid 140686654945024] mod_wsgi (pid=16): Callback registration for signal 28 ignored.
[Wed Sep 06 09:37:33.256509 2017] [wsgi:warn] [pid 16:tid 140686654945024] File "/tmp/mod_wsgi-localhost:5000:0/handler.wsgi", line 94, in <module>
[Wed Sep 06 09:37:33.256546 2017] [wsgi:warn] [pid 16:tid 140686654945024] recorder_directory=recorder_directory)
[Wed Sep 06 09:37:33.256563 2017] [wsgi:warn] [pid 16:tid 140686654945024] File "/usr/local/python/lib/python2.7/site-packages/mod_wsgi/server/__init__.py", line 1355, in __init__
[Wed Sep 06 09:37:33.256642 2017] [wsgi:warn] [pid 16:tid 140686654945024] exec(code, self.module.__dict__)
[Wed Sep 06 09:37:33.256720 2017] [wsgi:warn] [pid 16:tid 140686654945024] File "/app/myapp.py", line 325, in <module>
[Wed Sep 06 09:37:33.256770 2017] [wsgi:warn] [pid 16:tid 140686654945024] signal.signal(signal.SIGWINCH, on_exit)
And even if I solve the problem below info taken by official documentation is bothering me:
Do note that if enabling the ability to register signal handlers, such a registration can only reliably be done from within code which is implemented as a side effect of importing a script file identified by the WSGIImportScript directive. This is because signal handlers can only be registered from the main Python interpreter thread, and request handlers when using embedded mode and a multithreaded Apache MPM would generally execute from secondary threads. Similarly, when using daemon mode, request handlers would executed from secondary threads. Only code run as a side effect of WSGIImportScript is guaranteed to be executed in main Python interpreter thread.
Upvotes: 1
Views: 2793
Reputation: 58563
Do not use signals. Use the atexit
module in Python to register a callback. The callback will then be called when the process is being shutdown.
Upvotes: 1