From 26a93b9558b044f31243295e1e4a9b4632d6e633 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Thu, 12 May 2016 08:46:45 -0400 Subject: [PATCH] Generalize UWSGI specific setup. --- README.md | 42 ++++++------------- meta/main.yml | 2 +- tasks/nginx.yaml | 2 +- tasks/supervisor.yaml | 2 +- .../app_uwsgi_nginx.conf => app_nginx.conf} | 7 ++-- .../{supervisor => }/app_supervisor.conf | 6 +-- vars/main.yml | 7 +++- 7 files changed, 28 insertions(+), 40 deletions(-) rename templates/{nginx/app_uwsgi_nginx.conf => app_nginx.conf} (65%) rename templates/{supervisor => }/app_supervisor.conf (65%) diff --git a/README.md b/README.md index 9b11fa7..8006376 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ Requirements ------------ - 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 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 -app_name, app_nginx_hostname and app_uwsgi_executable parameters especially. +app_name, app_nginx_hostname and app_service_command parameters especially. - hosts: servers sudo: yes roles: - - { role: nginx-uwsgi-supervisor, + - { role: nginx-supervisor, app_name: app, app_nginx_hostname: app.domain.net, - app_uwsgi_port: 8080, - app_uwsgi_executable: "app.build:make_wsgi_app()" } + app_service_command: app_executable --port 9000 } 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: @@ -63,17 +61,13 @@ into sections and described below: - The path to the static elements of the site (templates, CSS, images, etc.) - Default: app_root_path/app_name/static/ -### UWSGI +### App Specific -- app_uwsgi_port: - - The port number that the WSGI runs on and accepts requests forwarded from NGINX. - - Default: 8001 -- app_uwsgi_executable: - - The method executed by UWSGI to create a WSGI running app. Usually a WSGI factory method or module in the app. - - Default: app:make_wsgi_app() -- app_uwsgi_envs: - - (Optional) A dictionary of environment variables to pass into an app. - - Default: empty dictionary +- app_service_command: + - The full command to execute to run the application +- app_service_stop_signal: + - The signal used to gracefully stop the application. + - Default: QUIT (as in SIGQUIT) ### General Web @@ -111,25 +105,15 @@ work with your setup: - web_user: - The non-root user who is allowed to control web + app servers on the target machine. - 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: - The filename of the NGINX configuration for the app. - - Default: app_name_uwsgi_nginx.conf + - Default: app_name_nginx.conf - supervisor_app_config: - The filename of the supervisor configuration for the app. - Default: app_name_supervisor.conf -- uwsgi_config_path: - - The path to the UWSGI configurations. - - Default: /srv/www/config/uwsgi -- 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 +- app_service_name: + - The name of the service setup for the app according to supervisor. + - Default: app_name License ------- diff --git a/meta/main.yml b/meta/main.yml index 4c3c473..612e60b 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,7 +1,7 @@ --- galaxy_info: 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 license: BSD min_ansible_version: 1.6 diff --git a/tasks/nginx.yaml b/tasks/nginx.yaml index 9e3f0fa..302823b 100644 --- a/tasks/nginx.yaml +++ b/tasks/nginx.yaml @@ -4,7 +4,7 @@ sudo: yes - 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 - name: link to enable nginx configuration diff --git a/tasks/supervisor.yaml b/tasks/supervisor.yaml index 6069d5b..af603fe 100644 --- a/tasks/supervisor.yaml +++ b/tasks/supervisor.yaml @@ -20,6 +20,6 @@ sudo: yes - 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 notify: start supervisord diff --git a/templates/nginx/app_uwsgi_nginx.conf b/templates/app_nginx.conf similarity index 65% rename from templates/nginx/app_uwsgi_nginx.conf rename to templates/app_nginx.conf index 125ba5b..74a9960 100644 --- a/templates/nginx/app_uwsgi_nginx.conf +++ b/templates/app_nginx.conf @@ -9,10 +9,9 @@ server { } location / { - try_files $uri @yourapplication; + try_files $uri @{{app_name}}_app; } - location @yourapplication { - include uwsgi_params; - uwsgi_pass 127.0.0.1:{{ app_uwsgi_port }}; + location @{{app_name}}_app { + # TODO: Find way to stitch together templates. } } \ No newline at end of file diff --git a/templates/supervisor/app_supervisor.conf b/templates/app_supervisor.conf similarity index 65% rename from templates/supervisor/app_supervisor.conf rename to templates/app_supervisor.conf index 553740b..2d09106 100644 --- a/templates/supervisor/app_supervisor.conf +++ b/templates/app_supervisor.conf @@ -1,8 +1,8 @@ ; UWSGI for {{ app_name }} -[program:{{ uwsgi_app_service_name }}] +[program:{{ app_service_name }}] user={{ web_server_group }} -command={{ uwsgi_venv }}/bin/uwsgi --ini {{ uwsgi_config_path }}/{{ uwsgi_app_ini }} -stopsignal=QUIT +command={{ app_service_command }} +stopsignal={{ app_service_stop_signal }} stdout_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-application.log stdout_logfile_backups = 5 stderr_logfile = {{ web_root_path }}/logs/supervisor/{{ app_name }}-error.log diff --git a/vars/main.yml b/vars/main.yml index c700403..41ae9d0 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -5,7 +5,12 @@ web_user: "{{ ansible_env.SUDO_USER }}" # NGINX -nginx_app_config: "{{ app_name }}_uwsgi_nginx.conf" +nginx_app_config: "{{ app_name }}_nginx.conf" # Supervisor 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