From 5531662527e4622e902edccae04f3f1465953ef2 Mon Sep 17 00:00:00 2001 From: Ross Perkins Date: Fri, 7 Nov 2014 18:55:13 -0800 Subject: [PATCH 1/6] No longer implicitly delete files ending in ".default", if you want to delete those, name them in the pillar. --- nginx/source.sls | 5 ----- 1 file changed, 5 deletions(-) diff --git a/nginx/source.sls b/nginx/source.sls index ea0eade..e462429 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -240,11 +240,6 @@ nginx: - absent watch: - cmd: nginx -{{ conf_dir }}/{{ file }}.default: - file: - - absent - watch: - - cmd: nginx {% endfor %} {% for file in nginx.get('delete_htdocs', []) %} From ce0e3384eb398e3aa56f2ce6986abf1bdb503fa3 Mon Sep 17 00:00:00 2001 From: Ross Perkins Date: Fri, 7 Nov 2014 18:56:07 -0800 Subject: [PATCH 2/6] Added optional 'service_name' pillar config, to change the name of the service from 'nginx' to whatever you want it to be. --- nginx/source.sls | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nginx/source.sls b/nginx/source.sls index e462429..b03deea 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -24,6 +24,8 @@ {% set without_items = nginx.get('without', []) -%} {% set make_flags = nginx.get('make_flags', nginx_map['make_flags']) -%} +{% set service_name = nginx.get('service_name', 'nginx') %} + {% set nginx_package = source + '/nginx-' + version + '.tar.gz' -%} {% set nginx_source = source + "/nginx-" + version -%} {% set nginx_modules_dir = source + "/nginx-modules" -%} @@ -215,7 +217,7 @@ nginx: file: - managed - template: jinja - - name: /etc/init.d/nginx + - name: /etc/init.d/{{ service_name }} - source: salt://nginx/templates/nginx.init.jinja - user: root - group: root @@ -227,6 +229,7 @@ nginx: - running - enable: True - restart: True + - name: {{ service_name }} - watch: - cmd: nginx - file: {{ conf_dir }}/nginx.conf From 5cad1002fc2c1112d101f9d1bfc1e194a94dfac2 Mon Sep 17 00:00:00 2001 From: Ross Perkins Date: Fri, 7 Nov 2014 18:56:28 -0800 Subject: [PATCH 3/6] Fixed some dependencies --- nginx/source.sls | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/nginx/source.sls b/nginx/source.sls index b03deea..be4c26c 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -212,8 +212,6 @@ nginx: {% for name, module in nginx.get('modules', {}).items() -%} - file: get-nginx-{{name}} {% endfor %} - - require_in: - - service: nginx file: - managed - template: jinja @@ -241,14 +239,14 @@ nginx: {{ conf_dir }}/{{ file }}: file: - absent - watch: - - cmd: nginx + - require_in: + - service: nginx {% endfor %} {% for file in nginx.get('delete_htdocs', []) %} {{ install_prefix }}/html/{{ file }}: file: - absent - watch: - - cmd: nginx + - require_in: + - service: nginx {% endfor %} From 3a158a278ca9033eea40d183805597c757764523 Mon Sep 17 00:00:00 2001 From: Ross Perkins Date: Fri, 7 Nov 2014 18:57:24 -0800 Subject: [PATCH 4/6] Added optional ability to NOT start nginx after compiling and installing --- nginx/source.sls | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nginx/source.sls b/nginx/source.sls index be4c26c..7ac0e91 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -25,6 +25,7 @@ {% set make_flags = nginx.get('make_flags', nginx_map['make_flags']) -%} {% set service_name = nginx.get('service_name', 'nginx') %} +{% set service_enable = nginx.get('service_enable', True) %} {% set nginx_package = source + '/nginx-' + version + '.tar.gz' -%} {% set nginx_source = source + "/nginx-" + version -%} @@ -224,9 +225,14 @@ nginx: sbin_dir: {{ sbin_dir }} pid_path: {{ pid_path }} service: +{% if service_enable %} - running - enable: True - restart: True +{% else %} + - dead + - enable: False +{% endif %} - name: {{ service_name }} - watch: - cmd: nginx From 2a679f95972dbcfbcc59d416674d3a0e104aa36c Mon Sep 17 00:00:00 2001 From: Ross Perkins Date: Fri, 7 Nov 2014 21:55:54 -0800 Subject: [PATCH 5/6] Update init.d script to allow custom service name --- nginx/source.sls | 1 + nginx/templates/nginx.init.jinja | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/nginx/source.sls b/nginx/source.sls index 7ac0e91..c900147 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -222,6 +222,7 @@ nginx: - group: root - mode: 0755 - context: + service_name: {{ service_name }} sbin_dir: {{ sbin_dir }} pid_path: {{ pid_path }} service: diff --git a/nginx/templates/nginx.init.jinja b/nginx/templates/nginx.init.jinja index 2ed3c91..e3086c7 100644 --- a/nginx/templates/nginx.init.jinja +++ b/nginx/templates/nginx.init.jinja @@ -1,23 +1,23 @@ #!/bin/sh ### BEGIN INIT INFO -# Provides: nginx +# Provides: {{ service_name }} # Required-Start: $local_fs $remote_fs $network $syslog # Required-Stop: $local_fs $remote_fs $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 -# Short-Description: starts the nginx web server -# Description: starts nginx using start-stop-daemon +# Short-Description: starts the {{ service_name }} web server +# Description: starts {{ service_name }} using start-stop-daemon ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON={{ sbin_dir }}/nginx -NAME=nginx -DESC=nginx +NAME={{ service_name }} +DESC={{ service_name }} # Include nginx defaults if available -if [ -f /etc/default/nginx ]; then - . /etc/default/nginx +if [ -f /etc/default/$NAME ]; then + . /etc/default/$NAME fi test -x $DAEMON || exit 0 From da9498bb45e75b96e74f98186377d6fbdde0b84b Mon Sep 17 00:00:00 2001 From: Ross Perkins Date: Fri, 7 Nov 2014 23:24:42 -0800 Subject: [PATCH 6/6] Fixed is-nginx-source-modified in the case where you're using a Github tarball as the URL, and it unzips to some freaky directory name instead of a nice name like we expected. --- nginx/source.sls | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nginx/source.sls b/nginx/source.sls index c900147..6fb2d7e 100644 --- a/nginx/source.sls +++ b/nginx/source.sls @@ -81,7 +81,7 @@ get-nginx: - file: {{ nginx_modules_dir }} cmd.wait: - cwd: {{ source }} - - name: tar -zxf {{ nginx_package }} + - name: tar --transform "s,^$(tar --list -zf nginx-{{ version }}.tar.gz | head -n 1),nginx-{{ version }}/," -zxf {{ nginx_package }} - require: - pkg: get-nginx - file: get-nginx @@ -117,12 +117,17 @@ get-ngx_devel_kit: - file: get-ngx_devel_kit {% endif %} -nginx-source-modified: +is-nginx-source-modified: cmd.run: - - cwd: {{ nginx_source }} + - cwd: {{ source }} - stateful: True - names: - - m=$(find . \! -name "build.*" -newer {{ sbin_dir }}/nginx -print -quit); + - 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); r=$?; if [ x$r != x0 ]; then echo "changed=yes comment='binary file does not exist or other find error'"; @@ -135,7 +140,7 @@ nginx-source-modified: echo "changed=no comment='source files are older than binary'" {% for name, module in nginx.get('modules', {}).items() -%} -nginx-module-modified-{{name}}: +is-nginx-module-modified-{{name}}: cmd.run: - cwd: {{ nginx_modules_dir }}/{{name}} - stateful: True @@ -196,9 +201,9 @@ nginx: {% endif %} - watch: - cmd: get-nginx - - cmd: nginx-source-modified + - cmd: is-nginx-source-modified {% for name, module in nginx.get('modules', {}).items() -%} - - cmd: nginx-module-modified-{{name}} + - cmd: is-nginx-module-modified-{{name}} - file: get-nginx-{{name}} {% endfor %} {% if use_sysvinit %}