-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from cchurch/uwsgi-support
Add uWSGI support.
- Loading branch information
Showing
8 changed files
with
130 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
|
||
- name: remove uwsgi system package | ||
apt: | ||
pkg: uwsgi | ||
state: absent | ||
|
||
- name: install uwsgi | ||
pip: | ||
name: uwsgi | ||
state: present | ||
version: "{{ uwsgi_version|default(omit) }}" | ||
virtualenv: "{{ venv_dir }}" | ||
virtualenv_python: /usr/bin/python{{ python_version }} | ||
become_user: "{{ project_user }}" | ||
vars: | ||
ansible_ssh_pipelining: true | ||
|
||
- name: configure uwsgi service | ||
template: | ||
src: uwsgi.service.j2 | ||
dest: /etc/systemd/system/{{ project_name }}-uwsgi.service | ||
owner: root | ||
group: root | ||
mode: 0644 | ||
|
||
- name: configure uwsgi ini | ||
template: | ||
src: uwsgi.ini.j2 | ||
dest: "{{ uwsgi_ini_path }}" | ||
owner: "{{ project_user }}" | ||
group: "{{ project_user }}" | ||
mode: 0644 | ||
|
||
- name: ensure uwsgi is enabled | ||
systemd: | ||
name: "{{ project_name }}-uwsgi.service" | ||
enabled: true | ||
daemon_reload: true | ||
|
||
# TODO: let connections to the {{ project_port }} through the firewall if we are load-balancing. | ||
|
||
# Use manage.sh so we use the same env vars from .env that we use on | ||
# other invocations of django manage.py. Unfortunately that means we cannot | ||
# use the ansible django_manage module. | ||
# TODO: see if we could use an ansible lookup plugin to read the .env file | ||
# and pass the values to the environment configuration item? | ||
- name: migrate | ||
shell: "{{ root_dir }}/manage.sh migrate --noinput -v 0" | ||
args: | ||
chdir: "{{ django_dir }}" | ||
become_user: "{{ project_user }}" | ||
run_once: true | ||
vars: | ||
ansible_ssh_pipelining: true | ||
|
||
- name: restart uwsgi | ||
systemd: | ||
name: "{{ project_name }}-uwsgi.service" | ||
state: restarted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{{ ansible_managed | comment }} | ||
|
||
[uwsgi] | ||
|
||
enable-threads = true | ||
single-interpreter = true | ||
master = true | ||
processes = {{ uwsgi_processes | default(10) }} | ||
vacuum = true | ||
uid = {{ project_user }} | ||
gid = {{ project_user }} | ||
die-on-term = true | ||
|
||
http = :{{ project_port }} | ||
socket = /tmp/{{ project_name }}.sock | ||
chmod-socket = 664 | ||
|
||
chdir = {{ source_dir }} | ||
module = {{ wsgi_module }} | ||
|
||
{{ uwsgi_extra_ini_settings | default('') }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{ ansible_managed | comment }} | ||
|
||
[Unit] | ||
Description={{ project_name }} uWSGI | ||
After=syslog.target | ||
|
||
[Service] | ||
Environment=DJANGO_SETTINGS_MODULE={{ project_settings }} | ||
ExecStart={{ django_dir }}/dotenv.sh \ | ||
{% if use_newrelic %}{{ venv_dir }}/bin/newrelic-admin run-program {% endif %} \ | ||
{{ venv_dir }}/bin/uwsgi \ | ||
--ini {{ uwsgi_ini_path }} | ||
Restart=on-failure | ||
KillSignal=SIGQUIT | ||
Type=notify | ||
StandardError=syslog | ||
NotifyAccess=all | ||
|
||
[Install] | ||
WantedBy=multi-user.target |