在Apache和mod_wsgi下运行的Django应用程序在每个Ansible剧本执行后重新开始。
我的要求是运行多个playbooks并行运行。 后台线程(在服务器启动时创build)从文件系统中select一个可用的播放,并提交给一个线程池,以便并行运行
我的应用程序configuration如下所示:
<VirtualHost *:1234> SSLEngine On SSLCertificateFile <path to cert file> SSLCertificateKeyFile <path to key file> ServerName example <Location /> SSLRequireSSL </Location> WSGIDaemonProcess myapp user=user group=user WSGIProcessGroup myapp WSGIScriptAlias / /home/user/test-wsgi.py CustomLog /var/log/myapp/access.log vhost_combined </VirtualHost>
我的脚本flie
import os import sys import site # Add the site-packages of the chosen virtualenv to work with site.addsitedir('~/.virtualenvs/myapp/local/lib/python2.7/site-packages') # Add the app's directory to the PYTHONPATH sys.path.append('/home/user/workspace/myproject/') sys.path.append('/home/user/workspace/myproject/myapp/settings/') os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings.dev' # Activate your virtual env activate_env=os.path.expanduser("~/.virtualenvs/myapp/bin/activate_this.py") execfile(activate_env, dict(__file__=activate_env)) import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
示例剧本
--- - hosts: all vars: tasks: - name: sample ping ping:
下面的日志说我的剧本执行失败,并立即mod_wsgi重新启动我的应用程序。
[Wed Sep 07 22:44:01 2016] [error] [Wed Sep 07 22:44:01 2016] [error] failed: True [Wed Sep 07 22:44:01 2016] [error] [Wed Sep 07 22:44:01 2016] [error] msg: Request failed
httpd错误日志
[Wed Sep 07 22:44:01 2016] [info] mod_wsgi (pid=1593): Shutdown requested 'myapp'. [Wed Sep 07 22:44:01 2016] [info] mod_wsgi (pid=1593): Stopping process 'myapp'. [Wed Sep 07 22:44:01 2016] [info] mod_wsgi (pid=1593): Destroying interpreters. [Wed Sep 07 22:44:01 2016] [info] mod_wsgi (pid=1593): Destroy interpreter 'example:1234|'. [Wed Sep 07 22:44:06 2016] [info] mod_wsgi (pid=1593): Aborting process 'myapp'. [Wed Sep 07 22:44:06 2016] [info] mod_wsgi (pid=1593): Exiting process 'myapp'. [Wed Sep 07 17:44:07 2016] [info] mod_wsgi (pid=1593): Process 'myapp' has died, deregister and restart it. [Wed Sep 07 17:44:07 2016] [info] mod_wsgi (pid=1593): Process 'myapp' has been deregistered and will no longer be monitored. [Wed Sep 07 17:44:07 2016] [info] mod_wsgi (pid=1688): Starting process 'myapp' with uid=50001, gid=50001 and threads=15. [Wed Sep 07 17:44:07 2016] [info] mod_wsgi (pid=1688): Initializing Python. [Wed Sep 07 17:44:07 2016] [info] mod_wsgi (pid=1688): Attach interpreter ''. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 0 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 1 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 2 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 3 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 4 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 5 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 6 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 7 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 8 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 9 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 11 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 10 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 12 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 14 in daemon process 'myapp'. [Wed Sep 07 17:44:07 2016] [debug] src/server/mod_wsgi.c(7980): mod_wsgi (pid=1688): Started thread 13 in daemon process 'myapp'.
为什么mod_wsgi重新启动我的应用程序,以及如何限制?