From bc51ffbd2bf0c8a6bb6886785abbead254f5836b Mon Sep 17 00:00:00 2001 From: Ari Aosved Date: Tue, 4 Nov 2014 18:45:53 -0800 Subject: [PATCH 1/2] Rebuild nginx if the source files, or module source files, are newer than the nginx binary --- nginx/source.sls | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/nginx/source.sls b/nginx/source.sls index b4da976..d73cc6b 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -113,6 +113,42 @@ get-ngx_devel_kit: - file: get-ngx_devel_kit {% endif %} +nginx-source-modified: + cmd.run: + - cwd: {{ nginx_source }} + - 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='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() -%} +nginx-module-modified-{{name}}: + 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 -%} + nginx: cmd.wait: - cwd: {{ nginx_source }} @@ -156,7 +192,9 @@ nginx: {% endif %} - watch: - cmd: get-nginx + - cmd: nginx-source-modified {% for name, module in nginx.get('modules', {}).items() -%} + - cmd: nginx-module-modified-{{name}} - file: get-nginx-{{name}} {% endfor %} {% if use_sysvinit %} From 7a3c370f355f61d4050c9e26d24cb3fd973fc616 Mon Sep 17 00:00:00 2001 From: Ari Aosved Date: Thu, 6 Nov 2014 18:18:27 -0800 Subject: [PATCH 2/2] allow the url to the source tarball to be overridden --- nginx/source.sls | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nginx/source.sls b/nginx/source.sls index d73cc6b..ea0eade 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -6,6 +6,7 @@ {% set nginx = pillar.get('nginx', {}) -%} {% set use_sysvinit = nginx.get('use_sysvinit', nginx_map['use_sysvinit']) %} {% set version = nginx.get('version', '1.6.2') -%} +{% set tarball_url = nginx.get('tarball_url', 'http://nginx.org/download/nginx-' + version + '.tar.gz') -%} {% set checksum = nginx.get('checksum', 'sha256=b5608c2959d3e7ad09b20fc8f9e5bd4bc87b3bc8ba5936a513c04ed8f1391a18') -%} {% set home = nginx.get('home', nginx_map['home']) -%} {% set base_temp_dir = nginx.get('base_temp_dir', '/tmp') -%} @@ -71,7 +72,7 @@ get-nginx: - libssl-dev file.managed: - name: {{ nginx_package }} - - source: http://nginx.org/download/nginx-{{ version }}.tar.gz + - source: {{ tarball_url }} - source_hash: {{ checksum }} - require: - file: {{ nginx_modules_dir }}