Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to disable service manager detection #1

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ wsgi_virtualenv: "{{deploy_dir|default('/opt/wsgi')}}/env"
wsgi_virtualenv_python: python

wsgi_service: upstart
wsgi_service_autodetect: true # Try to detect wsgi_service

# UWSGI default options (can be redefined for each wsgi app)
wsgi_uwsgi_enable_threads: no
Expand Down Expand Up @@ -60,3 +61,5 @@ wsgi_log_rotate_options:
- dateext
- rotate 7
- size 10M

nginx_sites_dir: /etc/nginx/conf.d/
14 changes: 14 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@
- name: wsgi restart
service: name={{item.name}}-wsgi state=restarted
with_items: "{{wsgi_applications}}"
become: yes

- name: wsgi reload
service: name={{item.name}}-wsgi state=reloaded
with_items: "{{wsgi_applications}}"
become: yes

- name: nginx restart
service: name=nginx state=restarted
become: yes

- name: nginx reload
service: name=nginx state=reloaded
become: yes

- name: reload systemd
become: yes
command: systemctl daemon-reload
1 change: 0 additions & 1 deletion meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

dependencies:
- Stouts.python
- Stouts.nginx

galaxy_info:
author: klen
Expand Down
4 changes: 4 additions & 0 deletions tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
template: src=upstart-{{item.server|default(wsgi_server)}}.conf.j2 dest=/etc/init/{{item.name}}-wsgi.conf owner=root group=root mode=0644
with_items: "{{wsgi_applications}}"
when: wsgi_service == 'upstart'
become: yes
notify: wsgi restart

- name: Setup Init
template: src=init-{{item.server|default(wsgi_server)}}.j2 dest=/etc/init.d/{{item.name}}-wsgi owner=root group=root mode=0755
with_items: "{{wsgi_applications}}"
when: wsgi_service == 'init'
become: yes
notify: wsgi restart

- name: Setup SystemD
template: src=systemd-{{item.server|default(wsgi_server)}}.j2 dest=/etc/systemd/system/{{item.name}}-wsgi.service owner=root group=root mode=0644
with_items: "{{wsgi_applications}}"
when: wsgi_service == 'systemd'
become: yes
notify: wsgi restart

- name: Ensure that the services are started
service: name={{item.name}}-wsgi state=started enabled=yes
become: yes
ignore_errors: yes
with_items: "{{wsgi_applications}}"
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
# vim:sw=2:ft=ansible

- include: wsgi.yml
- import_tasks: wsgi.yml
when: wsgi_enabled
tags: [wsgi]
13 changes: 9 additions & 4 deletions tasks/wsgi.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
---

- include_vars: "{{ansible_distribution}}.yml"
when: wsgi_service_autodetect

- include: dirs.yml
- import_tasks: dirs.yml
tags: [wsgi, wsgi-dirs]

- include: virtualenv.yml
- import_tasks: virtualenv.yml
tags: [wsgi, wsgi-virtualenv]

- include: configure.yml
- import_tasks: configure.yml
tags: [wsgi, wsgi-configure]

- name: Setup Nginx configurations
template: src=nginx.conf.j2 dest={{item.etc_dir|default("/opt/%s/etc" % item.name)}}/{{item.name}}-nginx.conf owner={{wsgi_user}} group={{wsgi_group}}
when: item.proxy|default(wsgi_proxy) == 'nginx'
with_items: "{{wsgi_applications}}"
notify: nginx reload
notify:
- nginx reload
- reload systemd
tags: [wsgi, wsgi-nginx]

- name: Enable nginx sites
file: state=link dest={{nginx_sites_dir}}/{{item.name}}.conf src={{item.etc_dir|default("/opt/%s/etc" % item.name)}}/{{item.name}}-nginx.conf
when: item.proxy|default(wsgi_proxy) == 'nginx'
with_items: "{{wsgi_applications}}"
become: yes
tags: [wsgi, wsgi-nginx]

- name: Configure log rotation
template: src=logrotate.conf.j2 dest=/etc/logrotate.d/{{item.name}}-wsgi.conf
with_items: "{{wsgi_applications}}"
when: wsgi_log_rotate
become: yes
tags: [wsgi, wsgi-logrotate]

# vim:sw=2:ft=ansible
4 changes: 2 additions & 2 deletions test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
- Stouts.nginx
- Stouts.python
tasks:
- include: tasks/main.yml
- import_tasks: tasks/main.yml
handlers:
- include: handlers/main.yml
- import_tasks: handlers/main.yml
vars_files:
- defaults/main.yml
- tests/vars.yml