2014-10-31 17:22:16 +01:00
|
|
|
{% from "nginx/map.jinja" import nginx as nginx_map with context %}
|
|
|
|
|
2014-10-20 10:59:16 +02:00
|
|
|
# Source currently requires package 'build-essential' which is Debian based.
|
2014-10-31 17:22:16 +01:00
|
|
|
# Will not work with os_family RedHat!
|
|
|
|
# TODO- Someone with a RedHat system please update this to work on RedHat
|
2013-08-21 21:01:51 +02:00
|
|
|
{% set nginx = pillar.get('nginx', {}) -%}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set use_sysvinit = nginx.get('use_sysvinit', nginx_map['use_sysvinit']) %}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% set version = nginx.get('version', '1.6.2') -%}
|
2014-11-07 03:18:27 +01:00
|
|
|
{% set tarball_url = nginx.get('tarball_url', 'http://nginx.org/download/nginx-' + version + '.tar.gz') -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% set checksum = nginx.get('checksum', 'sha256=b5608c2959d3e7ad09b20fc8f9e5bd4bc87b3bc8ba5936a513c04ed8f1391a18') -%}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set home = nginx.get('home', nginx_map['home']) -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% set base_temp_dir = nginx.get('base_temp_dir', '/tmp') -%}
|
2013-08-21 21:01:51 +02:00
|
|
|
{% set source = nginx.get('source_root', '/usr/local/src') -%}
|
|
|
|
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set conf_dir = nginx.get('conf_dir', nginx_map['conf_dir']) -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% set conf_only = nginx.get('conf_only', false) -%}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set log_dir = nginx.get('log_dir', nginx_map['log_dir']) -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% set pid_path = nginx.get('pid_path', '/var/run/nginx.pid') -%}
|
|
|
|
{% set lock_path = nginx.get('lock_path', '/var/lock/nginx.lock') -%}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set sbin_dir = nginx.get('sbin_dir', nginx_map['sbin_dir']) -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set install_prefix = nginx.get('install_prefix', nginx_map['install_prefix']) -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% set with_items = nginx.get('with', ['debug', 'http_dav_module', 'http_stub_status_module', 'pcre', 'ipv6']) -%}
|
|
|
|
{% set without_items = nginx.get('without', []) -%}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% set make_flags = nginx.get('make_flags', nginx_map['make_flags']) -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
|
2014-11-08 03:56:07 +01:00
|
|
|
{% set service_name = nginx.get('service_name', 'nginx') %}
|
2014-11-08 03:57:24 +01:00
|
|
|
{% set service_enable = nginx.get('service_enable', True) %}
|
2014-11-08 03:56:07 +01:00
|
|
|
|
2013-08-21 21:01:51 +02:00
|
|
|
{% set nginx_package = source + '/nginx-' + version + '.tar.gz' -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% set nginx_source = source + "/nginx-" + version -%}
|
2013-08-21 21:01:51 +02:00
|
|
|
{% set nginx_modules_dir = source + "/nginx-modules" -%}
|
|
|
|
|
|
|
|
include:
|
2014-05-30 18:28:59 +02:00
|
|
|
- nginx.common
|
2014-10-18 07:33:57 +02:00
|
|
|
{% if nginx.get('with_luajit', false) %}
|
2013-08-21 21:01:51 +02:00
|
|
|
- nginx.luajit2
|
|
|
|
{% endif -%}
|
2014-10-18 07:33:57 +02:00
|
|
|
{% if nginx.get('with_openresty', false) %}
|
2013-08-21 21:01:51 +02:00
|
|
|
- nginx.openresty
|
|
|
|
{% endif -%}
|
|
|
|
|
2014-10-18 07:33:57 +02:00
|
|
|
|
2013-08-21 21:01:51 +02:00
|
|
|
nginx_group:
|
|
|
|
group.present:
|
2014-10-31 17:22:16 +01:00
|
|
|
- name: {{ nginx_map.default_group }}
|
2013-08-21 21:01:51 +02:00
|
|
|
|
|
|
|
nginx_user:
|
|
|
|
file.directory:
|
|
|
|
- name: {{ home }}
|
2014-10-31 17:22:16 +01:00
|
|
|
- user: {{ nginx_map.default_user }}
|
|
|
|
- group: {{ nginx_map.default_group }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- mode: 0755
|
|
|
|
- require:
|
|
|
|
- user: nginx_user
|
|
|
|
- group: nginx_group
|
|
|
|
user.present:
|
2014-10-31 17:22:16 +01:00
|
|
|
- name: {{ nginx_map.default_user }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- home: {{ home }}
|
|
|
|
- groups:
|
2014-10-31 17:22:16 +01:00
|
|
|
- {{ nginx_map.default_group }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- require:
|
|
|
|
- group: nginx_group
|
|
|
|
|
2014-10-18 07:33:57 +02:00
|
|
|
{{ nginx_modules_dir }}:
|
|
|
|
file:
|
|
|
|
- directory
|
|
|
|
- makedirs: True
|
|
|
|
|
2013-08-21 21:01:51 +02:00
|
|
|
get-nginx:
|
|
|
|
pkg.installed:
|
|
|
|
- names:
|
|
|
|
- libpcre3-dev
|
|
|
|
- build-essential
|
|
|
|
- libssl-dev
|
|
|
|
file.managed:
|
|
|
|
- name: {{ nginx_package }}
|
2014-11-07 03:18:27 +01:00
|
|
|
- source: {{ tarball_url }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- source_hash: {{ checksum }}
|
2014-10-31 17:22:16 +01:00
|
|
|
- require:
|
|
|
|
- file: {{ nginx_modules_dir }}
|
2013-08-21 21:01:51 +02:00
|
|
|
cmd.wait:
|
|
|
|
- cwd: {{ source }}
|
2014-11-08 08:24:42 +01:00
|
|
|
- name: tar --transform "s,^$(tar --list -zf nginx-{{ version }}.tar.gz | head -n 1),nginx-{{ version }}/," -zxf {{ nginx_package }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- require:
|
|
|
|
- pkg: get-nginx
|
2014-10-31 17:22:16 +01:00
|
|
|
- file: get-nginx
|
2013-08-21 21:01:51 +02:00
|
|
|
- watch:
|
|
|
|
- file: get-nginx
|
|
|
|
|
2013-09-27 20:59:01 +02:00
|
|
|
{% for name, module in nginx.get('modules', {}).items() -%}
|
2013-08-21 21:01:51 +02:00
|
|
|
get-nginx-{{name}}:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ nginx_modules_dir }}/{{name}}.tar.gz
|
|
|
|
- source: {{ module['source'] }}
|
|
|
|
- source_hash: {{ module['source_hash'] }}
|
|
|
|
cmd.wait:
|
2014-10-18 07:33:57 +02:00
|
|
|
- cwd: {{ nginx_modules_dir }}
|
2013-09-27 20:59:01 +02:00
|
|
|
- names:
|
2014-10-18 07:33:57 +02:00
|
|
|
- tar --transform "s,^$(tar --list -zf {{name}}.tar.gz | head -n 1),{{name}}/," -zxf {{name}}.tar.gz
|
2013-08-21 21:01:51 +02:00
|
|
|
- watch:
|
2014-10-18 07:33:57 +02:00
|
|
|
- file: get-nginx-{{name}}
|
2013-08-21 21:01:51 +02:00
|
|
|
- require_in:
|
2014-05-30 18:31:00 +02:00
|
|
|
- cmd: nginx
|
2013-08-21 21:01:51 +02:00
|
|
|
{% endfor -%}
|
|
|
|
|
2014-10-18 07:33:57 +02:00
|
|
|
{% if nginx.get('ngx_devel_kit', true) -%}
|
2013-08-21 21:01:51 +02:00
|
|
|
get-ngx_devel_kit:
|
|
|
|
file.managed:
|
|
|
|
- name: {{ source }}/ngx_devel_kit.tar.gz
|
|
|
|
- source: https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz
|
|
|
|
- source_hash: sha1=e21ba642f26047661ada678b21eef001ee2121d8
|
|
|
|
cmd.wait:
|
2014-10-18 07:33:57 +02:00
|
|
|
- cwd: {{ source }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- name: tar -zxf {{ source }}/ngx_devel_kit.tar.gz -C {{ source }}
|
|
|
|
- watch:
|
|
|
|
- file: get-ngx_devel_kit
|
2014-10-18 07:33:57 +02:00
|
|
|
{% endif %}
|
2013-08-21 21:01:51 +02:00
|
|
|
|
2014-11-08 08:24:42 +01:00
|
|
|
is-nginx-source-modified:
|
2014-11-05 03:45:53 +01:00
|
|
|
cmd.run:
|
2014-11-08 08:24:42 +01:00
|
|
|
- cwd: {{ source }}
|
2014-11-05 03:45:53 +01:00
|
|
|
- stateful: True
|
|
|
|
- names:
|
2014-11-08 08:24:42 +01:00
|
|
|
- if [ ! -d "nginx-{{ version }}" ]; then
|
|
|
|
echo "changed=yes comment='Tarball has not yet been extracted'";
|
|
|
|
exit 0;
|
|
|
|
fi;
|
|
|
|
cd "nginx-{{ version }}";
|
|
|
|
m=$(find . \! -name "build.*" -newer {{ sbin_dir }}/nginx -print -quit);
|
2014-11-05 03:45:53 +01:00
|
|
|
r=$?;
|
|
|
|
if [ x$r != x0 ]; then
|
|
|
|
echo "changed=yes comment='binary file does not exist or other find error'";
|
|
|
|
exit 0;
|
|
|
|
fi;
|
|
|
|
if [ x$m != "x" ]; then
|
|
|
|
echo "changed=yes comment='source files are newer than binary'";
|
|
|
|
exit 0;
|
|
|
|
fi;
|
|
|
|
echo "changed=no comment='source files are older than binary'"
|
|
|
|
|
|
|
|
{% for name, module in nginx.get('modules', {}).items() -%}
|
2014-11-08 08:24:42 +01:00
|
|
|
is-nginx-module-modified-{{name}}:
|
2014-11-05 03:45:53 +01:00
|
|
|
cmd.run:
|
|
|
|
- cwd: {{ nginx_modules_dir }}/{{name}}
|
|
|
|
- stateful: True
|
|
|
|
- names:
|
|
|
|
- m=$(find . \! -name "build.*" -newer {{ sbin_dir }}/nginx -print -quit);
|
|
|
|
r=$?;
|
|
|
|
if [ x$r != x0 ]; then
|
|
|
|
echo "changed=yes comment='binary file does not exist or other find error'";
|
|
|
|
exit 0;
|
|
|
|
fi;
|
|
|
|
if [ x$m != "x" ]; then
|
|
|
|
echo "changed=yes comment='module source files are newer than binary'";
|
|
|
|
exit 0;
|
|
|
|
fi;
|
|
|
|
echo "changed=no comment='module source files are older than binary'"
|
|
|
|
{% endfor -%}
|
|
|
|
|
2013-08-21 21:01:51 +02:00
|
|
|
nginx:
|
|
|
|
cmd.wait:
|
2014-10-18 07:33:57 +02:00
|
|
|
- cwd: {{ nginx_source }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- names:
|
2014-10-31 17:54:15 +01:00
|
|
|
- (
|
|
|
|
./configure --conf-path={{ conf_dir }}/nginx.conf
|
2014-10-18 07:33:57 +02:00
|
|
|
--sbin-path={{ sbin_dir }}/nginx
|
2014-10-31 17:22:16 +01:00
|
|
|
--user={{ nginx_map.default_user }}
|
|
|
|
--group={{ nginx_map.default_group }}
|
2014-10-18 07:33:57 +02:00
|
|
|
--prefix={{ install_prefix }}
|
|
|
|
--http-log-path={{ log_dir }}/access.log
|
|
|
|
--error-log-path={{ log_dir }}/error.log
|
|
|
|
--pid-path={{ pid_path }}
|
|
|
|
--lock-path={{ lock_path }}
|
|
|
|
--http-client-body-temp-path={{ base_temp_dir }}/body
|
|
|
|
--http-proxy-temp-path={{ base_temp_dir }}/proxy
|
|
|
|
--http-fastcgi-temp-path={{ base_temp_dir }}/fastcgi
|
|
|
|
--http-uwsgi-temp-path={{ base_temp_dir }}/temp_uwsgi
|
|
|
|
--http-scgi-temp-path={{ base_temp_dir }}/temp_scgi
|
|
|
|
{%- for name, module in nginx.get('modules', {}).items() %}
|
|
|
|
--add-module={{nginx_modules_dir}}/{{name}}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- for name in with_items %}
|
|
|
|
--with-{{ name }}
|
|
|
|
{%- endfor %}
|
|
|
|
{%- for name in without_items %}
|
|
|
|
--without-{{ name }}
|
|
|
|
{%- endfor %}
|
|
|
|
&& make {{ make_flags }}
|
|
|
|
&& make install
|
2014-10-31 17:54:15 +01:00
|
|
|
)
|
|
|
|
{#- If they want to silence the compiler output, then save it to file so we can reference it later if needed #}
|
|
|
|
{%- if nginx.get('silence_compiler', true) %}
|
|
|
|
> {{ nginx_source }}/build.out 2> {{ nginx_source }}/build.err;
|
|
|
|
{#- If the build process failed, write stderr to stderr and exit with the error code #}
|
|
|
|
r=$?;
|
|
|
|
if [ x$r != x0 ]; then
|
|
|
|
cat {{ nginx_source }}/build.err 1>&2; {#- copy err output to stderr #}
|
|
|
|
exit $r;
|
|
|
|
fi;
|
|
|
|
{% endif %}
|
2013-08-21 21:01:51 +02:00
|
|
|
- watch:
|
|
|
|
- cmd: get-nginx
|
2014-11-08 08:24:42 +01:00
|
|
|
- cmd: is-nginx-source-modified
|
2014-10-18 07:33:57 +02:00
|
|
|
{% for name, module in nginx.get('modules', {}).items() -%}
|
2014-11-08 08:24:42 +01:00
|
|
|
- cmd: is-nginx-module-modified-{{name}}
|
2014-10-18 07:33:57 +02:00
|
|
|
- file: get-nginx-{{name}}
|
|
|
|
{% endfor %}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% if use_sysvinit %}
|
2014-10-20 10:59:16 +02:00
|
|
|
- watch_in:
|
|
|
|
{% set logger_types = ('access', 'error') %}
|
|
|
|
{% for log_type in logger_types %}
|
|
|
|
- service: nginx-logger-{{ log_type }}
|
|
|
|
{% endfor %}
|
2014-10-31 17:22:16 +01:00
|
|
|
{% endif %}
|
2013-08-21 21:01:51 +02:00
|
|
|
- require:
|
|
|
|
- cmd: get-nginx
|
2014-10-18 07:33:57 +02:00
|
|
|
{% for name, module in nginx.get('modules', {}).items() -%}
|
|
|
|
- file: get-nginx-{{name}}
|
|
|
|
{% endfor %}
|
|
|
|
file:
|
|
|
|
- managed
|
2013-08-21 21:01:51 +02:00
|
|
|
- template: jinja
|
2014-11-08 03:56:07 +01:00
|
|
|
- name: /etc/init.d/{{ service_name }}
|
2014-10-18 07:33:57 +02:00
|
|
|
- source: salt://nginx/templates/nginx.init.jinja
|
2013-08-21 21:01:51 +02:00
|
|
|
- user: root
|
|
|
|
- group: root
|
2014-10-18 07:33:57 +02:00
|
|
|
- mode: 0755
|
|
|
|
- context:
|
2014-11-08 06:55:54 +01:00
|
|
|
service_name: {{ service_name }}
|
2014-10-18 07:33:57 +02:00
|
|
|
sbin_dir: {{ sbin_dir }}
|
|
|
|
pid_path: {{ pid_path }}
|
|
|
|
service:
|
2014-11-08 03:57:24 +01:00
|
|
|
{% if service_enable %}
|
2014-10-18 07:33:57 +02:00
|
|
|
- running
|
2013-08-21 21:01:51 +02:00
|
|
|
- enable: True
|
2014-10-31 17:23:54 +01:00
|
|
|
- restart: True
|
2014-11-08 03:57:24 +01:00
|
|
|
{% else %}
|
|
|
|
- dead
|
|
|
|
- enable: False
|
|
|
|
{% endif %}
|
2014-11-08 03:56:07 +01:00
|
|
|
- name: {{ service_name }}
|
2013-08-21 21:01:51 +02:00
|
|
|
- watch:
|
2014-10-18 07:33:57 +02:00
|
|
|
- cmd: nginx
|
|
|
|
- file: {{ conf_dir }}/nginx.conf
|
2013-08-21 21:01:51 +02:00
|
|
|
- require:
|
|
|
|
- cmd: nginx
|
2014-10-18 07:33:57 +02:00
|
|
|
- file: {{ conf_dir }}/nginx.conf
|
|
|
|
|
|
|
|
{% for file in nginx.get('delete_confs', []) %}
|
|
|
|
{{ conf_dir }}/{{ file }}:
|
|
|
|
file:
|
|
|
|
- absent
|
2014-11-08 03:56:28 +01:00
|
|
|
- require_in:
|
|
|
|
- service: nginx
|
2014-10-18 07:33:57 +02:00
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
{% for file in nginx.get('delete_htdocs', []) %}
|
|
|
|
{{ install_prefix }}/html/{{ file }}:
|
|
|
|
file:
|
|
|
|
- absent
|
2014-11-08 03:56:28 +01:00
|
|
|
- require_in:
|
|
|
|
- service: nginx
|
2014-10-18 07:33:57 +02:00
|
|
|
{% endfor %}
|