From bc51ffbd2bf0c8a6bb6886785abbead254f5836b Mon Sep 17 00:00:00 2001 From: Ari Aosved Date: Tue, 4 Nov 2014 18:45:53 -0800 Subject: [PATCH] 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 %}