2014-08-12 04:54:22 +02:00
|
|
|
{% from "nginx/map.jinja" import nginx with context %}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set use_upstart = salt['pillar.get']('nginx:use_upstart', nginx['use_upstart']) %}
|
2014-05-04 20:14:03 +02:00
|
|
|
{% if use_upstart %}
|
2013-08-21 21:01:51 +02:00
|
|
|
nginx-old-init:
|
|
|
|
file:
|
|
|
|
- rename
|
|
|
|
- name: /usr/share/nginx/init.d
|
|
|
|
- source: /etc/init.d/nginx
|
|
|
|
- require_in:
|
|
|
|
- file: nginx
|
2014-10-20 10:59:16 +02:00
|
|
|
- require:
|
|
|
|
- pkg: nginx
|
2014-10-21 00:15:10 +02:00
|
|
|
- force: True
|
2014-10-20 10:59:16 +02:00
|
|
|
{% if grains.get('os_family') == 'Debian' %}
|
|
|
|
# Don't dpkg-divert if we are not Debian based!
|
2013-08-21 21:01:51 +02:00
|
|
|
cmd:
|
|
|
|
- wait
|
|
|
|
- name: dpkg-divert --divert /usr/share/nginx/init.d --add /etc/init.d/nginx
|
|
|
|
- require:
|
|
|
|
- module: nginx-old-init
|
|
|
|
- watch:
|
|
|
|
- file: nginx-old-init
|
|
|
|
- require_in:
|
|
|
|
- file: nginx
|
2014-10-20 10:59:16 +02:00
|
|
|
{% endif %}
|
2013-08-21 21:01:51 +02:00
|
|
|
module:
|
|
|
|
- wait
|
|
|
|
- name: cmd.run
|
|
|
|
- cmd: kill `cat /var/run/nginx.pid`
|
|
|
|
- watch:
|
|
|
|
- file: nginx-old-init
|
|
|
|
- require_in:
|
|
|
|
- file: nginx
|
|
|
|
|
2014-10-20 10:59:16 +02:00
|
|
|
# RedHat requires the init file in place to chkconfig off
|
|
|
|
{% if nginx['disable_before_rename'] %}
|
|
|
|
{% set _in = '_in' %}
|
|
|
|
{% else %}
|
|
|
|
{% set _in = '' %}
|
|
|
|
{% endif %}
|
|
|
|
|
2013-08-21 21:01:51 +02:00
|
|
|
nginx-old-init-disable:
|
|
|
|
cmd:
|
2014-10-20 10:59:16 +02:00
|
|
|
- run
|
|
|
|
- name: {{ nginx.old_init_disable }}
|
|
|
|
- require{{ _in }}:
|
2013-08-21 21:01:51 +02:00
|
|
|
- module: nginx-old-init
|
2014-10-20 10:59:16 +02:00
|
|
|
- unless: [ ! -f /etc/init.d/nginx ]
|
2014-05-04 20:14:03 +02:00
|
|
|
{% endif %}
|
2013-08-21 21:01:51 +02:00
|
|
|
|
2014-10-08 23:48:12 +02:00
|
|
|
{% if grains.get('os_family') == 'Debian' %}
|
|
|
|
|
|
|
|
{% set repo_source = pillar.get('nginx', {}).get('repo_source', 'default') %}
|
|
|
|
{% set use_ppa = repo_source == 'ppa' and grains.get('os') == 'Ubuntu' %}
|
|
|
|
{% set use_official = repo_source == 'official' and grains.get('os') in ('Ubuntu', 'Debian') %}
|
|
|
|
|
2014-08-12 04:54:22 +02:00
|
|
|
nginx-ppa-repo:
|
|
|
|
pkgrepo:
|
2014-10-08 23:48:12 +02:00
|
|
|
{%- if use_ppa %}
|
2014-08-12 04:54:22 +02:00
|
|
|
- managed
|
|
|
|
{%- else %}
|
|
|
|
- absent
|
|
|
|
{%- endif %}
|
|
|
|
- humanname: nginx-ppa-{{ grains['oscodename'] }}
|
2014-10-20 19:59:34 +02:00
|
|
|
- name: deb http://ppa.launchpad.net/nginx/{{ pillar.get('nginx', {}).get('repo_version', 'stable') }}/ubuntu {{ grains['oscodename'] }} main
|
|
|
|
- file: /etc/apt/sources.list.d/nginx-{{ pillar.get('nginx', {}).get('repo_version', 'stable') }}-{{ grains['oscodename'] }}.list
|
2014-08-12 04:54:22 +02:00
|
|
|
- dist: {{ grains['oscodename'] }}
|
|
|
|
- keyid: C300EE8C
|
|
|
|
- keyserver: keyserver.ubuntu.com
|
|
|
|
- require_in:
|
|
|
|
- pkg: nginx
|
|
|
|
- watch_in:
|
|
|
|
- pkg: nginx
|
2014-10-08 23:48:12 +02:00
|
|
|
|
|
|
|
nginx-official-repo:
|
|
|
|
pkgrepo:
|
|
|
|
{%- if use_official %}
|
|
|
|
- managed
|
|
|
|
{%- else %}
|
|
|
|
- absent
|
|
|
|
{%- endif %}
|
|
|
|
- humanname: nginx apt repo
|
|
|
|
- name: deb http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
|
|
|
|
- file: /etc/apt/sources.list.d/nginx-official-{{ grains['oscodename'] }}.list
|
|
|
|
- keyid: ABF5BD827BD9BF62
|
|
|
|
- keyserver: keyserver.ubuntu.com
|
|
|
|
- require_in:
|
|
|
|
- pkg: nginx
|
|
|
|
- watch_in:
|
|
|
|
- pkg: nginx
|
|
|
|
|
2014-08-12 04:54:22 +02:00
|
|
|
{% endif %}
|
|
|
|
|
2013-08-21 21:01:51 +02:00
|
|
|
nginx:
|
|
|
|
pkg.installed:
|
2014-08-12 04:54:22 +02:00
|
|
|
- name: {{ nginx.package }}
|
2014-05-04 20:14:03 +02:00
|
|
|
{% if use_upstart %}
|
2013-08-21 21:01:51 +02:00
|
|
|
file:
|
|
|
|
- managed
|
|
|
|
- name: /etc/init/nginx.conf
|
|
|
|
- template: jinja
|
|
|
|
- user: root
|
|
|
|
- group: root
|
|
|
|
- mode: 440
|
|
|
|
- source: salt://nginx/templates/upstart.jinja
|
|
|
|
- require:
|
|
|
|
- pkg: nginx
|
|
|
|
- file: nginx-old-init
|
2014-10-20 10:59:16 +02:00
|
|
|
- module: nginx-old-init
|
2014-05-04 20:14:03 +02:00
|
|
|
{% endif %}
|
2013-08-21 21:01:51 +02:00
|
|
|
service:
|
|
|
|
- running
|
|
|
|
- enable: True
|
|
|
|
- restart: True
|
|
|
|
- watch:
|
2014-05-04 20:14:03 +02:00
|
|
|
{% if use_upstart %}
|
2013-08-21 21:01:51 +02:00
|
|
|
- file: nginx
|
2014-05-04 20:14:03 +02:00
|
|
|
{% endif %}
|
2014-10-20 10:59:16 +02:00
|
|
|
{% set conf_dir = salt['pillar.get']('nginx:conf_dir', '/etc/nginx') %}
|
|
|
|
- file: {{ conf_dir }}/nginx.conf
|
|
|
|
- file: {{ conf_dir }}/conf.d/default.conf
|
|
|
|
- file: {{ conf_dir }}/conf.d/example_ssl.conf
|
2014-05-04 20:14:03 +02:00
|
|
|
- pkg: nginx
|
2014-06-19 16:43:00 +02:00
|
|
|
|
|
|
|
# Create 'service' symlink for tab completion.
|
2014-10-20 10:59:16 +02:00
|
|
|
# This is not supported in os_family RedHat and likely only works in
|
|
|
|
# Debian-based distros
|
|
|
|
{% if use_upstart and grains['os_family'] == 'Debian' %}
|
2014-06-19 16:43:00 +02:00
|
|
|
/etc/init.d/nginx:
|
|
|
|
file.symlink:
|
|
|
|
- target: /lib/init/upstart-job
|
2014-10-16 05:25:02 +02:00
|
|
|
- force: True
|
2014-06-19 16:43:00 +02:00
|
|
|
{% endif %}
|