Saltstack Official Nginx Formula
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

206 líneas
6.1KB

  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:
  104. cmd.wait:
  105. - cwd: {{ nginx_source }}
  106. - names:
  107. - ./configure --conf-path={{ conf_dir }}/nginx.conf
  108. --sbin-path={{ sbin_dir }}/nginx
  109. --user={{ nginx_map.default_user }}
  110. --group={{ nginx_map.default_group }}
  111. --prefix={{ install_prefix }}
  112. --http-log-path={{ log_dir }}/access.log
  113. --error-log-path={{ log_dir }}/error.log
  114. --pid-path={{ pid_path }}
  115. --lock-path={{ lock_path }}
  116. --http-client-body-temp-path={{ base_temp_dir }}/body
  117. --http-proxy-temp-path={{ base_temp_dir }}/proxy
  118. --http-fastcgi-temp-path={{ base_temp_dir }}/fastcgi
  119. --http-uwsgi-temp-path={{ base_temp_dir }}/temp_uwsgi
  120. --http-scgi-temp-path={{ base_temp_dir }}/temp_scgi
  121. {%- for name, module in nginx.get('modules', {}).items() %}
  122. --add-module={{nginx_modules_dir}}/{{name}}
  123. {%- endfor %}
  124. {%- for name in with_items %}
  125. --with-{{ name }}
  126. {%- endfor %}
  127. {%- for name in without_items %}
  128. --without-{{ name }}
  129. {%- endfor %}
  130. && make {{ make_flags }}
  131. && make install
  132. - watch:
  133. - cmd: get-nginx
  134. {% for name, module in nginx.get('modules', {}).items() -%}
  135. - file: get-nginx-{{name}}
  136. {% endfor %}
  137. {% if use_sysvinit %}
  138. - watch_in:
  139. {% set logger_types = ('access', 'error') %}
  140. {% for log_type in logger_types %}
  141. - service: nginx-logger-{{ log_type }}
  142. {% endfor %}
  143. {% endif %}
  144. - require:
  145. - cmd: get-nginx
  146. {% for name, module in nginx.get('modules', {}).items() -%}
  147. - file: get-nginx-{{name}}
  148. {% endfor %}
  149. - require_in:
  150. - service: nginx
  151. file:
  152. - managed
  153. - template: jinja
  154. - name: /etc/init.d/nginx
  155. - source: salt://nginx/templates/nginx.init.jinja
  156. - user: root
  157. - group: root
  158. - mode: 0755
  159. - context:
  160. sbin_dir: {{ sbin_dir }}
  161. pid_path: {{ pid_path }}
  162. service:
  163. - running
  164. - enable: True
  165. - reload: True
  166. - watch:
  167. - cmd: nginx
  168. - file: {{ conf_dir }}/nginx.conf
  169. - require:
  170. - cmd: nginx
  171. - file: {{ conf_dir }}/nginx.conf
  172. {% for file in nginx.get('delete_confs', []) %}
  173. {{ conf_dir }}/{{ file }}:
  174. file:
  175. - absent
  176. watch:
  177. - cmd: nginx
  178. {{ conf_dir }}/{{ file }}.default:
  179. file:
  180. - absent
  181. watch:
  182. - cmd: nginx
  183. {% endfor %}
  184. {% for file in nginx.get('delete_htdocs', []) %}
  185. {{ install_prefix }}/html/{{ file }}:
  186. file:
  187. - absent
  188. watch:
  189. - cmd: nginx
  190. {% endfor %}