Skip to content

Commit 78c2c8b

Browse files
committed
Fix #16: Properly configure mod_wsgi
1 parent 2a32c35 commit 78c2c8b

File tree

5 files changed

+59
-8
lines changed

5 files changed

+59
-8
lines changed

README.md

+21-5
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,24 @@ Optional Configuration variables
4040
- `conf.name`: The application name (machine name), the same as the Python app. Default: `{{ project }}`
4141
- `conf.python_version`: The python version to install (major.minor), default: `3.5`.
4242
- `conf.virtualenv_dir`: Virtualenvs home directory, default to vars' respective option.
43-
- `conf.wsgi_script`: The wsgi script, default: `index.wsgi`.
4443
- `conf.compile_msgs`: Set to `true` in order to compile i18n messages.
4544
- `conf.memcached`: Set to `true` in order to clear cache.
46-
- `conf.data`: A list of the dump files to load data from, eg `[project, auth]`, omit to skip loaddata. Depends on `loaddata` variable to be `true`.
47-
- `conf.https_only`: If true then configure Apache
48-
[only for SSL](https://github.com/Wtower/ansible-node-deploy/issues/6). Default: `false`.
45+
- `conf.data`: A list of the dump files to load data from, eg `[project, auth]`, omit to skip loaddata.
46+
Depends on `loaddata` variable to be `true`.
47+
48+
[WSGI](http://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html)
49+
50+
- `conf.wsgi_script`: The wsgi script, default: `index.wsgi`.
51+
- `conf.wsgi_threads`: If set mod_wsgi runs in daemon mode (**recommended** 3-25).
52+
53+
The following are used only for daemon mode:
54+
55+
- `conf.wsgi_processes`: If set mod_wsgi runs in multi-process mode (integer).
56+
- `conf.wsgi_inactivity_timeout`: Set only for small traffic sites to reset process and reclaim memory (eg. 300).
57+
- `conf.wsgi_restart_interval`: Set to let process restart after n seconds. Useful if process memory grows large.
58+
- `conf.wsgi_max_requests`: Similar to the above.
59+
- `conf.wsgi_graceful_timeout`: If any of the above two are set, the number of seconds to expect no requests to restart.
60+
- `conf.wsgi_queue_timeout`: If large request queues, drop requests after that many seconds.
4961

5062
Other default variables
5163
-----------------------
@@ -163,7 +175,11 @@ Task description
163175

164176
Reset target directory ownership to the appropriate Plesk permissions.
165177

166-
24. Configure Apache
178+
24. Touch WSGI script
179+
180+
Update the timestamp. If WSGI daemon mode it causes restart of the process at next request.
181+
182+
25. Configure Apache
167183

168184
Configure Apache to execute the wsgi script using the provided template file.
169185
Only executes if a `domain_name` is provided.

examples/django_sites.yml

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ django_sites:
88
dev_path: ~/workspace/python/project
99
host_path: /var/www/vhosts/mysite.com/myproject.com
1010
host_user: username
11+
wsgi_script: ninedev/wsgi_mod.py
12+
wsgi_threads: 3
13+
wsgi_inactivity_timeout: 300
1114
python_version: 3.4
1215
memcached: true
1316
https_only: true

tasks/main.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,21 @@
122122
state: directory
123123
become: true
124124

125+
- name: Update WSGI module timestamp
126+
file:
127+
name: "{{ conf.host_path }}/{{ conf.wsgi_script|default('index.wsgi') }}"
128+
state: touch
129+
125130
- name: Configure Apache
126131
template: src="vhost.conf.j2" dest="/var/www/vhosts/{{ conf.domain_name }}/conf/vhost.conf" backup=yes
127132
become: true
128-
when: conf.domain_name is defined and (conf.https_only is not defined or not conf.https_only)
133+
when: conf.domain_name is defined
129134
notify:
130135
- Reconfigure Plesk domain
131136
- Restart Apache
132137

133138
- name: Configure Apache SSL
134-
template: src="vhost.conf.j2" dest="/var/www/vhosts/{{ conf.domain_name }}/conf/vhost_ssl.conf" backup=yes
139+
template: src="vhost_ssl.conf.j2" dest="/var/www/vhosts/{{ conf.domain_name }}/conf/vhost_ssl.conf" backup=yes
135140
become: true
136141
when: conf.domain_name is defined
137142
notify:

templates/vhost.conf.j2

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# {{ ansible_managed }}
22

3-
WSGIScriptAlias / {{ conf.host_path }}/{{ conf.wsgi_script| default('index.wsgi') }}
3+
{% if conf.wsgi_threads is defined %}
4+
WSGIDaemonProcess {{ conf.domain_name }} display-name=django-{{ project }} threads={{ conf.wsgi_threads }}
5+
{%- if conf.wsgi_processes is defined %} processes={{ conf.wsgi_processes }}{% endif -%}
6+
{%- if conf.wsgi_inactivity_timeout is defined %} inactivity-timeout={{ conf.wsgi_inactivity_timeout }}{% endif -%}
7+
{%- if conf.wsgi_restart_interval is defined %} restart-interval={{ conf.wsgi_restart_interval }}{% endif -%}
8+
{%- if conf.wsgi_max_requests is defined %} maximum-requests={{ conf.wsgi_max_requests }}{% endif -%}
9+
{%- if conf.wsgi_graceful_timeout is defined %} graceful-timeout={{ conf.wsgi_graceful_timeout }}{% endif -%}
10+
{%- if conf.wsgi_queue_timeout is defined %} queue-timeout={{ conf.wsgi_queue_timeout }}{% endif %}
11+
12+
WSGIProcessGroup {{ conf.domain_name }}
13+
{% endif %}
14+
WSGIScriptAlias / {{ conf.host_path }}/{{ conf.wsgi_script|default('index.wsgi') }}
415

516
Alias /static/ {{ conf.host_path }}/static/
617
<Location "/static/">

templates/vhost_ssl.conf.j2

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# {{ ansible_managed }}
2+
3+
{% if conf.wsgi_threads is defined %}
4+
WSGIProcessGroup {{ conf.domain_name }}
5+
{% endif %}
6+
WSGIScriptAlias / {{ conf.host_path }}/{{ conf.wsgi_script|default('index.wsgi') }}
7+
8+
Alias /static/ {{ conf.host_path }}/static/
9+
<Location "/static/">
10+
Options -Indexes
11+
</Location>
12+
13+
Alias /media/ {{ conf.host_path }}/media/
14+
<Location "/media/">
15+
Options -Indexes
16+
</Location>

0 commit comments

Comments
 (0)