Background Image
Table of Contents Table of Contents
Previous Page  453 / 478 Next Page
Information
Show Menu
Previous Page 453 / 478 Next Page
Page Background

alias /home/harry/sites/{{ host }}/static;

}

location / {

proxy_set_header Host $host;

proxy_pass

http://unix

:/tmp/{{ host }}.socket;

}

}

Configuring Gunicorn, and Using Handlers to Restart

Services

Here’s the second half of our playbook:

deploy_tools/provision.ansible.yaml.

- name: write gunicorn init script

template: src=./gunicorn-upstart.conf.j2

dest=/etc/init/gunicorn-{{ host }}.conf

notify:

- restart gunicorn

- name: make sure nginx is running

service: name=nginx state=running

- name: make sure gunicorn is running

service: name=gunicorn-{{ host }} state=running

handlers:

- name: restart nginx

service: name=nginx state=restarted

- name: restart gunicorn

service: name=gunicorn-{{ host }} state=restarted

Once again we use a template for our Gunicorn config:

deploy_tools/gunicorn.upstart.conf.j2.

description

"Gunicorn server for {{ host }}"

start on net-device-up

stop on shutdown

respawn

chdir /home/harry/sites/

{{

host

}}

/source

exec

../virtualenv/bin/gunicorn

\

--bind unix:/tmp/

{{

host

}}

.socket

\

--access-logfile ../access.log

\

--error-logfile ../error.log

\

superlists

.wsgi:application

Then we have two “handlers” to restart Nginx and Gunicorn. Ansible is clever, so if it

sees multiple steps all call the same handlers, it waits until the last one before calling it.

Configuring Gunicorn, and Using Handlers to Restart Services

|

425