Saltstack Official Nginx Formula
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

190 lines
5.3KB

  1. {% set nginx = pillar.get('nginx', {}) -%}
  2. {% set version = nginx.get('version', '1.6.2') -%}
  3. {% set checksum = nginx.get('checksum', 'sha256=b5608c2959d3e7ad09b20fc8f9e5bd4bc87b3bc8ba5936a513c04ed8f1391a18') -%}
  4. {% set home = nginx.get('home', '/var/www') -%}
  5. {% set base_temp_dir = nginx.get('base_temp_dir', '/tmp') -%}
  6. {% set source = nginx.get('source_root', '/usr/local/src') -%}
  7. {% set conf_dir = nginx.get('conf_dir', '/etc/nginx') -%}
  8. {% set conf_only = nginx.get('conf_only', false) -%}
  9. {% set log_dir = nginx.get('log_dir', '/var/log/nginx') -%}
  10. {% set pid_path = nginx.get('pid_path', '/var/run/nginx.pid') -%}
  11. {% set lock_path = nginx.get('lock_path', '/var/lock/nginx.lock') -%}
  12. {% set sbin_dir = nginx.get('sbin_dir', '/usr/sbin') -%}
  13. {% set install_prefix = nginx.get('install_prefix', '/usr/local/nginx') -%}
  14. {% set with_items = nginx.get('with', ['debug', 'http_dav_module', 'http_stub_status_module', 'pcre', 'ipv6']) -%}
  15. {% set without_items = nginx.get('without', []) -%}
  16. {% set make_flags = nginx.get('make_flags', '-j2') -%}
  17. {% set nginx_package = source + '/nginx-' + version + '.tar.gz' -%}
  18. {% set nginx_source = source + "/nginx-" + version -%}
  19. {% set nginx_modules_dir = source + "/nginx-modules" -%}
  20. include:
  21. - nginx.common
  22. {% if nginx.get('with_luajit', false) %}
  23. - nginx.luajit2
  24. {% endif -%}
  25. {% if nginx.get('with_openresty', false) %}
  26. - nginx.openresty
  27. {% endif -%}
  28. nginx_group:
  29. group.present:
  30. - name: www-data
  31. nginx_user:
  32. file.directory:
  33. - name: {{ home }}
  34. - user: www-data
  35. - group: www-data
  36. - mode: 0755
  37. - require:
  38. - user: nginx_user
  39. - group: nginx_group
  40. user.present:
  41. - name: www-data
  42. - home: {{ home }}
  43. - groups:
  44. - www-data
  45. - require:
  46. - group: nginx_group
  47. {{ nginx_modules_dir }}:
  48. file:
  49. - directory
  50. - makedirs: True
  51. get-nginx:
  52. pkg.installed:
  53. - names:
  54. - libpcre3-dev
  55. - build-essential
  56. - libssl-dev
  57. file.managed:
  58. - name: {{ nginx_package }}
  59. - source: http://nginx.org/download/nginx-{{ version }}.tar.gz
  60. - source_hash: {{ checksum }}
  61. cmd.wait:
  62. - cwd: {{ source }}
  63. - name: tar -zxf {{ nginx_package }}
  64. - require:
  65. - pkg: get-nginx
  66. - watch:
  67. - file: get-nginx
  68. {% for name, module in nginx.get('modules', {}).items() -%}
  69. get-nginx-{{name}}:
  70. file.managed:
  71. - name: {{ nginx_modules_dir }}/{{name}}.tar.gz
  72. - source: {{ module['source'] }}
  73. - source_hash: {{ module['source_hash'] }}
  74. cmd.wait:
  75. - cwd: {{ nginx_modules_dir }}
  76. - names:
  77. - tar --transform "s,^$(tar --list -zf {{name}}.tar.gz | head -n 1),{{name}}/," -zxf {{name}}.tar.gz
  78. - watch:
  79. - file: get-nginx-{{name}}
  80. - require_in:
  81. - cmd: nginx
  82. {% endfor -%}
  83. {% if nginx.get('ngx_devel_kit', true) -%}
  84. get-ngx_devel_kit:
  85. file.managed:
  86. - name: {{ source }}/ngx_devel_kit.tar.gz
  87. - source: https://github.com/simpl/ngx_devel_kit/archive/v0.2.18.tar.gz
  88. - source_hash: sha1=e21ba642f26047661ada678b21eef001ee2121d8
  89. cmd.wait:
  90. - cwd: {{ source }}
  91. - name: tar -zxf {{ source }}/ngx_devel_kit.tar.gz -C {{ source }}
  92. - watch:
  93. - file: get-ngx_devel_kit
  94. {% endif %}
  95. nginx:
  96. cmd.wait:
  97. - cwd: {{ nginx_source }}
  98. - names:
  99. - ./configure --conf-path={{ conf_dir }}/nginx.conf
  100. --sbin-path={{ sbin_dir }}/nginx
  101. --user=www-data
  102. --group=www-data
  103. --prefix={{ install_prefix }}
  104. --http-log-path={{ log_dir }}/access.log
  105. --error-log-path={{ log_dir }}/error.log
  106. --pid-path={{ pid_path }}
  107. --lock-path={{ lock_path }}
  108. --http-client-body-temp-path={{ base_temp_dir }}/body
  109. --http-proxy-temp-path={{ base_temp_dir }}/proxy
  110. --http-fastcgi-temp-path={{ base_temp_dir }}/fastcgi
  111. --http-uwsgi-temp-path={{ base_temp_dir }}/temp_uwsgi
  112. --http-scgi-temp-path={{ base_temp_dir }}/temp_scgi
  113. {%- for name, module in nginx.get('modules', {}).items() %}
  114. --add-module={{nginx_modules_dir}}/{{name}}
  115. {%- endfor %}
  116. {%- for name in with_items %}
  117. --with-{{ name }}
  118. {%- endfor %}
  119. {%- for name in without_items %}
  120. --without-{{ name }}
  121. {%- endfor %}
  122. && make {{ make_flags }}
  123. && make install
  124. - watch:
  125. - cmd: get-nginx
  126. {% for name, module in nginx.get('modules', {}).items() -%}
  127. - file: get-nginx-{{name}}
  128. {% endfor %}
  129. - require:
  130. - cmd: get-nginx
  131. {% for name, module in nginx.get('modules', {}).items() -%}
  132. - file: get-nginx-{{name}}
  133. {% endfor %}
  134. - require_in:
  135. - service: nginx
  136. file:
  137. - managed
  138. - template: jinja
  139. - name: /etc/init.d/nginx
  140. - source: salt://nginx/templates/nginx.init.jinja
  141. - user: root
  142. - group: root
  143. - mode: 0755
  144. - context:
  145. sbin_dir: {{ sbin_dir }}
  146. pid_path: {{ pid_path }}
  147. service:
  148. - running
  149. - enable: True
  150. - reload: True
  151. - watch:
  152. - cmd: nginx
  153. - file: {{ conf_dir }}/nginx.conf
  154. - require:
  155. - cmd: nginx
  156. - file: {{ conf_dir }}/nginx.conf
  157. {% for file in nginx.get('delete_confs', []) %}
  158. {{ conf_dir }}/{{ file }}:
  159. file:
  160. - absent
  161. watch:
  162. - cmd: nginx
  163. {{ conf_dir }}/{{ file }}.default:
  164. file:
  165. - absent
  166. watch:
  167. - cmd: nginx
  168. {% endfor %}
  169. {% for file in nginx.get('delete_htdocs', []) %}
  170. {{ install_prefix }}/html/{{ file }}:
  171. file:
  172. - absent
  173. watch:
  174. - cmd: nginx
  175. {% endfor %}