Commit fa045f01 by Carson Gee

Merge pull request #1717 from mitodl/cg/gunicorn_conf_files

Convert active gunicorn services to use configuration file
parents cbd12247 36348a44
- Role: analytics-api, edxapp, ora, xqueue, xserver
- Switched gunicorn from using an entirely command argument based
configuration to usign python configuration files. Variables for
extra configuration in the configuration file template, and
command line argument overrides are available.
- Role: analytics-api, insights
- Using Django 1.7 migrate command.
......
......@@ -71,6 +71,7 @@ ANALYTICS_API_CONFIG:
ANALYTICS_API_GUNICORN_WORKERS: "2"
ANALYTICS_API_GUNICORN_EXTRA: ""
ANALYTICS_API_GUNICORN_EXTRA_CONF: ""
#
# vars are namespace with the module name.
#
......
......@@ -22,6 +22,13 @@
notify: "restart the analytics service"
sudo_user: "{{ analytics_api_user }}"
- name: "add gunicorn configuration file"
template: >
src=edx/app/analytics-api/analytics_api_gunicorn.py.j2
dest={{ analytics_api_app_dir }}/analytics_api_gunicorn.py
sudo_user: "{{ analytics_api_user }}"
notify: "restart the analytics service"
- name: write out app config file
template: >
src=edx/app/analytics-api/analytics-api.yaml.j2
......
......@@ -15,4 +15,4 @@ export NEW_RELIC_LICENSE_KEY="{{ NEWRELIC_LICENSE_KEY }}"
source {{ analytics_api_app_dir }}/analytics_api_env
{{ executable }} --pythonpath={{ analytics_api_code_dir }} -b {{ analytics_api_gunicorn_host }}:{{ analytics_api_gunicorn_port }} -w {{ ANALYTICS_API_GUNICORN_WORKERS }} --timeout={{ analytics_api_gunicorn_timeout }} {{ ANALYTICS_API_GUNICORN_EXTRA }} analyticsdataserver.wsgi:application
{{ executable }} -c {{ analytics_api_app_dir }}/analytics_api_gunicorn.py {{ ANALYTICS_API_GUNICORN_EXTRA }} analyticsdataserver.wsgi:application
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
{{ ansible_managed }}
"""
timeout = {{ analytics_api_gunicorn_timeout }}
bind = "{{ analytics_api_gunicorn_host }}:{{ analytics_api_gunicorn_port }}"
pythonpath = "{{ analytics_api_code_dir }}"
workers = {{ ANALYTICS_API_GUNICORN_WORKERS }}
{{ ANALYTICS_API_GUNICORN_EXTRA_CONF }}
......@@ -28,7 +28,10 @@ EDXAPP_PREVIEW_LMS_BASE: ""
EDXAPP_CMS_BASE: ""
EDXAPP_LMS_GUNICORN_EXTRA: ""
EDXAPP_LMS_GUNICORN_EXTRA_CONF: ""
EDXAPP_CMS_GUNICORN_EXTRA: ""
EDXAPP_CMS_GUNICORN_EXTRA_CONF: ""
# Set this to the maximum number
# of requests for gunicorn for the lms and cms
......
......@@ -60,6 +60,14 @@
group={{ supervisor_user }}
sudo_user: "{{ supervisor_user }}"
- name: "add gunicorn configuration files"
template: >
src={{ item }}_gunicorn.py.j2 dest={{ edxapp_app_dir }}/{{ item }}_gunicorn.py
with_items: service_variants_enabled
sudo_user: "{{ edxapp_user }}"
notify:
- restart edxapp
# write the supervisor script for celery workers
- name: writing celery worker supervisor script
......
......@@ -5,22 +5,8 @@
{% else -%}
{% set executable = edxapp_venv_dir + '/bin/gunicorn' -%}
{% endif -%}
{% if EDXAPP_CMS_MAX_REQ -%}
{% set max_req = '--max-requests ' + EDXAPP_CMS_MAX_REQ|string -%}
{% else -%}
{% set max_req = '' -%}
{% endif -%}
{% if EDXAPP_WORKERS -%}
command={{ executable }} {{ max_req }} --preload -b {{ edxapp_cms_gunicorn_host }}:{{ edxapp_cms_gunicorn_port }} -w {{ EDXAPP_WORKERS.cms }} --timeout=300 --pythonpath={{ edxapp_code_dir }} cms.wsgi
{% else -%}
{# This is for backwards compatibility, set workers explicitely using EDXAPP_WORKERS #}
{% if ansible_processor|length > 0 -%}
command={{ executable }} {{ max_req }} --preload -b {{ edxapp_cms_gunicorn_host }}:{{ edxapp_cms_gunicorn_port }} -w {{ ansible_processor|length * worker_core_mult.cms }} --timeout=300 --pythonpath={{ edxapp_code_dir }} {{ EDXAPP_CMS_GUNICORN_EXTRA }} cms.wsgi
{% else -%}
command={{ executable }} {{ max_req }} --preload -b {{ edxapp_cms_gunicorn_host }}:{{ edxapp_cms_gunicorn_port }} -w {{ worker_core_mult.cms }} --timeout=300 --pythonpath={{ edxapp_code_dir }} {{ EDXAPP_CMS_GUNICORN_EXTRA }} cms.wsgi
{% endif -%}
{% endif -%}
command={{ executable }} -c {{ edxapp_app_dir }}/cms_gunicorn.py {{ EDXAPP_CMS_GUNICORN_EXTRA }} cms.wsgi
user={{ common_web_user }}
directory={{ edxapp_code_dir }}
......
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
{{ ansible_managed }}
"""
import multiprocessing
preload_app = True
timeout = 300
bind = "{{ edxapp_cms_gunicorn_host }}:{{ edxapp_cms_gunicorn_port }}"
pythonpath = "{{ edxapp_code_dir }}"
{% if EDXAPP_CMS_MAX_REQ -%}
max_requests = {{ EDXAPP_CMS_MAX_REQ }}
{% endif -%}
{% if EDXAPP_WORKERS %}
workers = {{ EDXAPP_WORKERS }}
{% else %}
workers = (multiprocessing.cpu_count()-1) * {{ worker_core_mult.cms }} + {{ worker_core_mult.cms }}
{% endif %}
{{ EDXAPP_CMS_GUNICORN_EXTRA_CONF }}
......@@ -6,22 +6,7 @@
{% set executable = edxapp_venv_dir + '/bin/gunicorn' -%}
{% endif -%}
{% if EDXAPP_LMS_MAX_REQ -%}
{% set max_req = '--max-requests ' + EDXAPP_LMS_MAX_REQ|string -%}
{% else -%}
{% set max_req = '' -%}
{% endif -%}
{% if EDXAPP_WORKERS -%}
command={{ executable }} {{ max_req }} --preload -b {{ edxapp_lms_gunicorn_host }}:{{ edxapp_lms_gunicorn_port }} -w {{ EDXAPP_WORKERS.lms }} --timeout=300 --pythonpath={{ edxapp_code_dir }} lms.wsgi
{% else -%}
{# This is for backwards compatibility, set workers explicitely using EDXAPP_WORKERS #}
{% if ansible_processor|length > 0 -%}
command={{ executable }} {{ max_req }} --preload -b {{ edxapp_lms_gunicorn_host }}:{{ edxapp_lms_gunicorn_port }} -w {{ ansible_processor|length * worker_core_mult.lms }} --timeout=300 --pythonpath={{ edxapp_code_dir }} {{ EDXAPP_LMS_GUNICORN_EXTRA }} lms.wsgi
{% else -%}
command={{ executable }} {{ max_req }} --preload -b {{ edxapp_lms_gunicorn_host }}:{{ edxapp_lms_gunicorn_port }} -w {{ worker_core_mult.lms }} --timeout=300 --pythonpath={{ edxapp_code_dir }} {{ EDXAPP_LMS_GUNICORN_EXTRA }} lms.wsgi
{% endif %}
{% endif %}
command={{ executable }} -c {{ edxapp_app_dir }}/lms_gunicorn.py lms.wsgi
user={{ common_web_user }}
directory={{ edxapp_code_dir }}
......
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
{{ ansible_managed }}
"""
import multiprocessing
preload_app = True
timeout = 300
bind = "{{ edxapp_lms_gunicorn_host }}:{{ edxapp_lms_gunicorn_port }}"
pythonpath = "{{ edxapp_code_dir }}"
{% if EDXAPP_LMS_MAX_REQ -%}
max_requests = {{ EDXAPP_LMS_MAX_REQ }}
{% endif -%}
{% if EDXAPP_WORKERS %}
workers = {{ EDXAPP_WORKERS }}
{% else %}
workers = (multiprocessing.cpu_count()-1) * {{ worker_core_mult.lms }} + {{ worker_core_mult.lms }}
{% endif %}
{{ EDXAPP_LMS_GUNICORN_EXTRA_CONF }}
......@@ -2,6 +2,7 @@
---
ORA_NGINX_PORT: 18060
ORA_GUNICORN_EXTRA: ""
ORA_GUNICORN_EXTRA_CONF: ""
ora_app_dir: "{{ COMMON_APP_DIR }}/ora"
ora_code_dir: "{{ ora_app_dir }}/ora"
......
......@@ -19,6 +19,13 @@
with_items: ['ora', 'ora_celery']
when: not disable_edx_services
- name: "add gunicorn configuration file"
template: >
src=ora_gunicorn.py.j2 dest={{ ora_app_dir }}/ora_gunicorn.py
sudo_user: "{{ ora_user }}"
notify:
- restart ora
- include: ease.yml
- name: create ora application config
......
[program:ora]
command={{ ora_venv_bin }}/gunicorn --preload -b {{ ora_gunicorn_host }}:{{ ora_gunicorn_port }} -w {{ ora_gunicorn_workers }} --timeout=90 --pythonpath={{ ora_code_dir}} {{ ORA_GUNICORN_EXTRA }} edx_ora.wsgi
command={{ ora_venv_bin }}/gunicorn -c {{ ora_app_dir }}/ora_gunicorn.py {{ ORA_GUNICORN_EXTRA }} edx_ora.wsgi
user={{ common_web_user }}
directory={{ ora_code_dir }}
......
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
{{ ansible_managed }}
"""
preload_app = True
timeout = 90
bind = "{{ ora_gunicorn_host }}:{{ ora_gunicorn_port }}"
pythonpath = "{{ ora_code_dir }}"
workers = {{ ora_gunicorn_workers }}
{{ ORA_GUNICORN_EXTRA_CONF }}
......@@ -3,7 +3,7 @@
---
XQUEUE_NGINX_PORT: 18040
XQUEUE_GUNICORN_WORKERS_EXTRA: ""
XQUEUE_GUNICORN_EXTRA: ""
XQUEUE_GUNICORN_WORKERS_EXTRA_CONF: ""
XQUEUE_QUEUES:
# push queue
'edX-Open_DemoX': 'http://localhost:18050'
......
......@@ -13,6 +13,12 @@
with_items: ['xqueue', 'xqueue_consumer']
when: not disable_edx_services
- name: "add gunicorn configuration file"
template: >
src=xqueue_gunicorn.py.j2 dest={{ xqueue_app_dir }}/xqueue_gunicorn.py
sudo_user: "{{ xqueue_user }}"
notify:
- restart xqueue
- name: create xqueue application config
template: src=xqueue.env.json.j2 dest={{ xqueue_app_dir }}/xqueue.env.json mode=0644
......
......@@ -6,15 +6,7 @@
{% set executable = xqueue_venv_bin + '/gunicorn' %}
{% endif %}
{% if XQUEUE_WORKERS -%}
command={{ executable }} --preload -b {{ xqueue_gunicorn_host }}:{{ xqueue_gunicorn_port }} -w {{ XQUEUE_WORKERS }} --timeout=300 --pythonpath={{ xqueue_code_dir }} {{ XQUEUE_GUNICORN_WORKERS_EXTRA }} xqueue.wsgi
{% else -%}
{% if ansible_processor|length > 0 %}
command={{ executable }} --preload -b {{ xqueue_gunicorn_host }}:{{ xqueue_gunicorn_port }} -w {{ ansible_processor|length * 2 }} --timeout=300 --pythonpath={{ xqueue_code_dir }} {{ XQUEUE_GUNICORN_EXTRA }} xqueue.wsgi
{% else -%}
command={{ executable }} --preload -b {{ xqueue_gunicorn_host }}:{{ xqueue_gunicorn_port }} -w 2 --timeout=300 --pythonpath={{ xqueue_code_dir }} {{ XQUEUE_GUNICORN_EXTRA }} xqueue.wsgi
{% endif -%}
{% endif -%}
command={{ executable }} -c {{ xqueue_app_dir }}/xqueue_gunicorn.py {{ XQUEUE_GUNICORN_WORKERS_EXTRA }} xqueue.wsgi
user={{ common_web_user }}
directory={{ xqueue_code_dir }}
......
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
{{ ansible_managed }}
"""
import multiprocessing
preload_app = True
timeout = 300
bind = "{{ xqueue_gunicorn_host }}:{{ xqueue_gunicorn_port }}"
pythonpath = "{{ xqueue_code_dir }}"
{% if XQUEUE_WORKERS %}
workers = {{ XQUEUE_WORKERS }}
{% else %}
workers = (multiprocessing.cpu_count()-1) * 2 + 2
{% endif %}
{{ XQUEUE_GUNICORN_WORKERS_EXTRA_CONF }}
......@@ -4,6 +4,7 @@
XSERVER_NGINX_PORT: 18050
XSERVER_GUNICORN_EXTRA: ""
XSERVER_GUNICORN_EXTRA_CONF: ""
XSERVER_RUN_URL: ''
XSERVER_LOGGING_ENV: 'sandbox'
XSERVER_SYSLOG_SERVER: ''
......
......@@ -11,6 +11,13 @@
state=link force=yes
when: not disable_edx_services
- name: "add gunicorn configuration file"
template: >
src=xserver_gunicorn.py.j2 dest={{ xserver_app_dir }}/xserver_gunicorn.py
sudo_user: "{{ xserver_user }}"
notify:
- restart xserver
- name: checkout code
git: >
dest={{ xserver_code_dir }} repo={{ xserver_source_repo }} version={{xserver_version}}
......
[program:xserver]
command={{ xserver_venv_bin }}/gunicorn --preload -b {{ xserver_gunicorn_host }}:{{ xserver_gunicorn_port }} -w {{ xserver_gunicorn_workers }} --timeout=30 --pythonpath={{ xserver_code_dir }} {{ XSERVER_GUNICORN_EXTRA }} pyxserver_wsgi:application
command={{ xserver_venv_bin }}/gunicorn -c {{ xserver_app_dir }}/xserver_gunicorn.py {{ XSERVER_GUNICORN_EXTRA }} pyxserver_wsgi:application
user={{ common_web_user }}
directory={{ xserver_code_dir }}
......
"""
gunicorn configuration file: http://docs.gunicorn.org/en/develop/configure.html
{{ ansible_managed }}
"""
preload_app = True
timeout = 30
bind = "{{ xserver_gunicorn_host }}:{{ xserver_gunicorn_port }}"
pythonpath = "{{ xserver_code_dir }}"
workers = {{ xserver_gunicorn_workers }}
{{ XSERVER_GUNICORN_EXTRA_CONF }}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment