Generalize UWSGI specific setup.

This commit is contained in:
Dorian 2016-05-12 08:46:45 -04:00
parent 667761d299
commit 26a93b9558
7 changed files with 28 additions and 40 deletions

View File

@ -11,7 +11,6 @@ Requirements
------------ ------------
- aptitude or python-apt (required by apt tasks) - aptitude or python-apt (required by apt tasks)
- python > 2.5 (required by ini_file tasks)
This role is designed to work against a modern Ubuntu system. (Tested on Ubuntu 13.10 and 14.04) It should This role is designed to work against a modern Ubuntu system. (Tested on Ubuntu 13.10 and 14.04) It should
theoretically work on older versions of Ubuntu or Debian based systems. theoretically work on older versions of Ubuntu or Debian based systems.
@ -20,16 +19,15 @@ Example Playbook
---------------- ----------------
The simplest way to include the role in your playbook is to copy the below configuration. Remember to modify the The simplest way to include the role in your playbook is to copy the below configuration. Remember to modify the
app_name, app_nginx_hostname and app_uwsgi_executable parameters especially. app_name, app_nginx_hostname and app_service_command parameters especially.
- hosts: servers - hosts: servers
sudo: yes sudo: yes
roles: roles:
- { role: nginx-uwsgi-supervisor, - { role: nginx-supervisor,
app_name: app, app_name: app,
app_nginx_hostname: app.domain.net, app_nginx_hostname: app.domain.net,
app_uwsgi_port: 8080, app_service_command: app_executable --port 9000 }
app_uwsgi_executable: "app.build:make_wsgi_app()" }
The role itself is very configurable. For exaple, if you prefer the location of the web application to refer to the The role itself is very configurable. For exaple, if you prefer the location of the web application to refer to the
domain name rather than the default root path, then simply override the app_root_path variable with something like: domain name rather than the default root path, then simply override the app_root_path variable with something like:
@ -63,17 +61,13 @@ into sections and described below:
- The path to the static elements of the site (templates, CSS, images, etc.) - The path to the static elements of the site (templates, CSS, images, etc.)
- Default: app_root_path/app_name/static/ - Default: app_root_path/app_name/static/
### UWSGI ### App Specific
- app_uwsgi_port: - app_service_command:
- The port number that the WSGI runs on and accepts requests forwarded from NGINX. - The full command to execute to run the application
- Default: 8001 - app_service_stop_signal:
- app_uwsgi_executable: - The signal used to gracefully stop the application.
- The method executed by UWSGI to create a WSGI running app. Usually a WSGI factory method or module in the app. - Default: QUIT (as in SIGQUIT)
- Default: app:make_wsgi_app()
- app_uwsgi_envs:
- (Optional) A dictionary of environment variables to pass into an app.
- Default: empty dictionary
### General Web ### General Web
@ -111,25 +105,15 @@ work with your setup:
- web_user: - web_user:
- The non-root user who is allowed to control web + app servers on the target machine. - The non-root user who is allowed to control web + app servers on the target machine.
- Default: current user - Default: current user
- virtualenv_root_path:
- The common root directory of Python virtual environments associated with running the
UWSGI app + server.
- Default: /srv/www/virtualenvs/
- nginx_app_conf: - nginx_app_conf:
- The filename of the NGINX configuration for the app. - The filename of the NGINX configuration for the app.
- Default: app_name_uwsgi_nginx.conf - Default: app_name_nginx.conf
- supervisor_app_config: - supervisor_app_config:
- The filename of the supervisor configuration for the app. - The filename of the supervisor configuration for the app.
- Default: app_name_supervisor.conf - Default: app_name_supervisor.conf
- uwsgi_config_path: - app_service_name:
- The path to the UWSGI configurations. - The name of the service setup for the app according to supervisor.
- Default: /srv/www/config/uwsgi - Default: app_name
- uwsgi_app_ini:
- The filename of the UWSGI INI configuration for the app.
- Default: app_name_uwsgi.ini
- uwsgi_service_name:
- The name of the UWSGI setup for the app according to supervisor.
- Default: app_name_uwsgi
License License
------- -------

View File

@ -1,7 +1,7 @@
--- ---
galaxy_info: galaxy_info:
author: Dorian Pula author: Dorian Pula
description: An elegant NGINX, UWSGI and supervisor Ansible role description: An elegant NGINX and supervisor Ansible base role
company: Amber Penguin Software company: Amber Penguin Software
license: BSD license: BSD
min_ansible_version: 1.6 min_ansible_version: 1.6

View File

@ -4,7 +4,7 @@
sudo: yes sudo: yes
- name: configure nginx - name: configure nginx
template: src=nginx/app_uwsgi_nginx.conf dest=/etc/nginx/sites-available/{{ nginx_app_config }} template: src=app_nginx.conf dest=/etc/nginx/sites-available/{{ nginx_app_config }}
sudo: yes sudo: yes
- name: link to enable nginx configuration - name: link to enable nginx configuration

View File

@ -20,6 +20,6 @@
sudo: yes sudo: yes
- name: upload supervisor configuration to web server home - name: upload supervisor configuration to web server home
template: src=supervisor/app_supervisor.conf dest=/etc/supervisor/conf.d/{{ supervisor_app_config }} template: src=app_supervisor.conf dest=/etc/supervisor/conf.d/{{ supervisor_app_config }}
sudo: yes sudo: yes
notify: start supervisord notify: start supervisord

View File

@ -9,10 +9,9 @@ server {
} }
location / { location / {
try_files $uri @yourapplication; try_files $uri @{{app_name}}_app;
} }
location @yourapplication { location @{{app_name}}_app {
include uwsgi_params; # TODO: Find way to stitch together templates.
uwsgi_pass 127.0.0.1:{{ app_uwsgi_port }};
} }
} }

View File

@ -1,8 +1,8 @@
; UWSGI for {{ app_name }} ; UWSGI for {{ app_name }}
[program:{{ uwsgi_app_service_name }}] [program:{{ app_service_name }}]
user={{ web_server_group }} user={{ web_server_group }}
command={{ uwsgi_venv }}/bin/uwsgi --ini {{ uwsgi_config_path }}/{{ uwsgi_app_ini }} command={{ app_service_command }}
stopsignal=QUIT stopsignal={{ app_service_stop_signal }}
stdout_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-application.log stdout_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-application.log
stdout_logfile_backups = 5 stdout_logfile_backups = 5
stderr_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-error.log stderr_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-error.log

View File

@ -5,7 +5,12 @@
web_user: "{{ ansible_env.SUDO_USER }}" web_user: "{{ ansible_env.SUDO_USER }}"
# NGINX # NGINX
nginx_app_config: "{{ app_name }}_uwsgi_nginx.conf" nginx_app_config: "{{ app_name }}_nginx.conf"
# Supervisor # Supervisor
supervisor_app_config: "{{ app_name }}_supervisor.conf" supervisor_app_config: "{{ app_name }}_supervisor.conf"
# App specific configuration
app_service_name: "{{ app_name }}"
app_service_command: "echo {{ app_name }}"
app_service_stop_signal: QUIT