Saltstack Official Nginx Formula
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

256 linhas
7.9KB

  1. {% from "nginx/map.jinja" import nginx as nginx_map with context %}
  2. # Source currently requires package 'build-essential' which is Debian based.
  3. # Will not work with os_family RedHat!
  4. # TODO- Someone with a RedHat system please update this to work on RedHat
  5. {% set nginx = pillar.get('nginx', {}) -%}
  6. {% set use_sysvinit = nginx.get('use_sysvinit', nginx_map['use_sysvinit']) %}
  7. {% set version = nginx.get('version', '1.6.2') -%}
  8. {% set checksum = nginx.get('checksum', 'sha256=b5608c2959d3e7ad09b20fc8f9e5bd4bc87b3bc8ba5936a513c04ed8f1391a18') -%}
  9. {% set home = nginx.get('home', nginx_map['home']) -%}
  10. {% set base_temp_dir = nginx.get('base_temp_dir', '/tmp') -%}
  11. {% set source = nginx.get('source_root', '/usr/local/src') -%}
  12. {% set conf_dir = nginx.get('conf_dir', nginx_map['conf_dir']) -%}
  13. {% set conf_only = nginx.get('conf_only', false) -%}
  14. {% set log_dir = nginx.get('log_dir', nginx_map['log_dir']) -%}
  15. {% set pid_path = nginx.get('pid_path', '/var/run/nginx.pid') -%}
  16. {% set lock_path = nginx.get('lock_path', '/var/lock/nginx.lock') -%}
  17. {% set sbin_dir = nginx.get('sbin_dir', nginx_map['sbin_dir']) -%}
  18. {% set install_prefix = nginx.get('install_prefix', nginx_map['install_prefix']) -%}
  19. {% set with_items = nginx.get('with', ['debug', 'http_dav_module', 'http_stub_status_module', 'pcre', 'ipv6']) -%}
  20. {% set without_items = nginx.get('without', []) -%}
  21. {% set make_flags = nginx.get('make_flags', nginx_map['make_flags']) -%}
  22. {% set nginx_package = source + '/nginx-' + version + '.tar.gz' -%}
  23. {% set nginx_source = source + "/nginx-" + version -%}
  24. {% set nginx_modules_dir = source + "/nginx-modules" -%}
  25. include:
  26. - nginx.common
  27. {% if nginx.get('with_luajit', false) %}
  28. - nginx.luajit2
  29. {% endif -%}
  30. {% if nginx.get('with_openresty', false) %}
  31. - nginx.openresty
  32. {% endif -%}
  33. nginx_group:
  34. group.present:
  35. - name: {{ nginx_map.default_group }}
  36. nginx_user:
  37. file.directory:
  38. - name: {{ home }}
  39. - user: {{ nginx_map.default_user }}
  40. - group: {{ nginx_map.default_group }}
  41. - mode: 0755
  42. - require:
  43. - user: nginx_user
  44. - group: nginx_group
  45. user.present:
  46. - name: {{ nginx_map.default_user }}
  47. - home: {{ home }}
  48. - groups:
  49. - {{ nginx_map.default_group }}
  50. - require:
  51. - group: nginx_group
  52. {{ nginx_modules_dir }}:
  53. file:
  54. - directory
  55. - makedirs: True
  56. get-nginx:
  57. pkg.installed:
  58. - names:
  59. - libpcre3-dev
  60. - build-essential
  61. - libssl-dev
  62. file.managed:
  63. - name: {{ nginx_package }}
  64. - source: http://nginx.org/download/nginx-{{ version }}.tar.gz
  65. - source_hash: {{ checksum }}
  66. - require:
  67. - file: {{ nginx_modules_dir }}
  68. cmd.wait:
  69. - cwd: {{ source }}
  70. - name: tar -zxf {{ nginx_package }}
  71. - require:
  72. - pkg: get-nginx
  73. - file: get-nginx
  74. - watch:
  75. - file: get-nginx
  76. {% for name, module in nginx.get('modules', {}).items() -%}
  77. get-nginx-{{name}}:
  78. file.managed:
  79. - name: {{ nginx_modules_dir }}/{{name}}.tar.gz
  80. - source: {{ module['source'] }}
  81. - source_hash: {{ module['source_hash'] }}
  82. cmd.wait:
  83. - cwd: {{ nginx_modules_dir }}
  84. - names:
  85. - tar --transform "s,^$(tar --list -zf {{name}}.tar.gz | head -n 1),{{name}}/," -zxf {{name}}.tar.gz
  86. - watch:
  87. - file: get-nginx-{{name}}
  88. - require_in:
  89. - cmd: nginx
  90. {% endfor -%}
  91. {% if nginx.get('ngx_devel_kit', true) -%}
  92. get-ngx_devel_kit:
  93. file.managed:
  94. - name: {{ source }}/ngx_devel_kit.tar.gz
  95. - source: https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz
  96. - source_hash: sha1=e21ba642f26047661ada678b21eef001ee2121d8
  97. cmd.wait:
  98. - cwd: {{ source }}
  99. - name: tar -zxf {{ source }}/ngx_devel_kit.tar.gz -C {{ source }}
  100. - watch:
  101. - file: get-ngx_devel_kit
  102. {% endif %}
  103. nginx-source-modified:
  104. cmd.run:
  105. - cwd: {{ nginx_source }}
  106. - stateful: True
  107. - names:
  108. - m=$(find . \! -name "build.*" -newer {{ sbin_dir }}/nginx -print -quit);
  109. r=$?;
  110. if [ x$r != x0 ]; then
  111. echo "changed=yes comment='binary file does not exist or other find error'";
  112. exit 0;
  113. fi;
  114. if [ x$m != "x" ]; then
  115. echo "changed=yes comment='source files are newer than binary'";
  116. exit 0;
  117. fi;
  118. echo "changed=no comment='source files are older than binary'"
  119. {% for name, module in nginx.get('modules', {}).items() -%}
  120. nginx-module-modified-{{name}}:
  121. cmd.run:
  122. - cwd: {{ nginx_modules_dir }}/{{name}}
  123. - stateful: True
  124. - names:
  125. - m=$(find . \! -name "build.*" -newer {{ sbin_dir }}/nginx -print -quit);
  126. r=$?;
  127. if [ x$r != x0 ]; then
  128. echo "changed=yes comment='binary file does not exist or other find error'";
  129. exit 0;
  130. fi;
  131. if [ x$m != "x" ]; then
  132. echo "changed=yes comment='module source files are newer than binary'";
  133. exit 0;
  134. fi;
  135. echo "changed=no comment='module source files are older than binary'"
  136. {% endfor -%}
  137. nginx:
  138. cmd.wait:
  139. - cwd: {{ nginx_source }}
  140. - names:
  141. - (
  142. ./configure --conf-path={{ conf_dir }}/nginx.conf
  143. --sbin-path={{ sbin_dir }}/nginx
  144. --user={{ nginx_map.default_user }}
  145. --group={{ nginx_map.default_group }}
  146. --prefix={{ install_prefix }}
  147. --http-log-path={{ log_dir }}/access.log
  148. --error-log-path={{ log_dir }}/error.log
  149. --pid-path={{ pid_path }}
  150. --lock-path={{ lock_path }}
  151. --http-client-body-temp-path={{ base_temp_dir }}/body
  152. --http-proxy-temp-path={{ base_temp_dir }}/proxy
  153. --http-fastcgi-temp-path={{ base_temp_dir }}/fastcgi
  154. --http-uwsgi-temp-path={{ base_temp_dir }}/temp_uwsgi
  155. --http-scgi-temp-path={{ base_temp_dir }}/temp_scgi
  156. {%- for name, module in nginx.get('modules', {}).items() %}
  157. --add-module={{nginx_modules_dir}}/{{name}}
  158. {%- endfor %}
  159. {%- for name in with_items %}
  160. --with-{{ name }}
  161. {%- endfor %}
  162. {%- for name in without_items %}
  163. --without-{{ name }}
  164. {%- endfor %}
  165. && make {{ make_flags }}
  166. && make install
  167. )
  168. {#- If they want to silence the compiler output, then save it to file so we can reference it later if needed #}
  169. {%- if nginx.get('silence_compiler', true) %}
  170. > {{ nginx_source }}/build.out 2> {{ nginx_source }}/build.err;
  171. {#- If the build process failed, write stderr to stderr and exit with the error code #}
  172. r=$?;
  173. if [ x$r != x0 ]; then
  174. cat {{ nginx_source }}/build.err 1>&2; {#- copy err output to stderr #}
  175. exit $r;
  176. fi;
  177. {% endif %}
  178. - watch:
  179. - cmd: get-nginx
  180. - cmd: nginx-source-modified
  181. {% for name, module in nginx.get('modules', {}).items() -%}
  182. - cmd: nginx-module-modified-{{name}}
  183. - file: get-nginx-{{name}}
  184. {% endfor %}
  185. {% if use_sysvinit %}
  186. - watch_in:
  187. {% set logger_types = ('access', 'error') %}
  188. {% for log_type in logger_types %}
  189. - service: nginx-logger-{{ log_type }}
  190. {% endfor %}
  191. {% endif %}
  192. - require:
  193. - cmd: get-nginx
  194. {% for name, module in nginx.get('modules', {}).items() -%}
  195. - file: get-nginx-{{name}}
  196. {% endfor %}
  197. - require_in:
  198. - service: nginx
  199. file:
  200. - managed
  201. - template: jinja
  202. - name: /etc/init.d/nginx
  203. - source: salt://nginx/templates/nginx.init.jinja
  204. - user: root
  205. - group: root
  206. - mode: 0755
  207. - context:
  208. sbin_dir: {{ sbin_dir }}
  209. pid_path: {{ pid_path }}
  210. service:
  211. - running
  212. - enable: True
  213. - restart: True
  214. - watch:
  215. - cmd: nginx
  216. - file: {{ conf_dir }}/nginx.conf
  217. - require:
  218. - cmd: nginx
  219. - file: {{ conf_dir }}/nginx.conf
  220. {% for file in nginx.get('delete_confs', []) %}
  221. {{ conf_dir }}/{{ file }}:
  222. file:
  223. - absent
  224. watch:
  225. - cmd: nginx
  226. {{ conf_dir }}/{{ file }}.default:
  227. file:
  228. - absent
  229. watch:
  230. - cmd: nginx
  231. {% endfor %}
  232. {% for file in nginx.get('delete_htdocs', []) %}
  233. {{ install_prefix }}/html/{{ file }}:
  234. file:
  235. - absent
  236. watch:
  237. - cmd: nginx
  238. {% endfor %}