Saltstack Official Nginx Formula
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 satır
3.6KB

  1. {% from "nginx/map.jinja" import nginx with context %}
  2. {% set use_upstart = salt['pillar.get']('nginx:use_upstart', nginx['use_upstart']) %}
  3. {% if use_upstart %}
  4. nginx-old-init:
  5. file.rename:
  6. - name: /usr/share/nginx/init.d
  7. - source: /etc/init.d/nginx
  8. - require_in:
  9. - file: nginx
  10. - require:
  11. - pkg: nginx
  12. - force: True
  13. {% if grains.get('os_family') == 'Debian' %}
  14. # Don't dpkg-divert if we are not Debian based!
  15. cmd.wait:
  16. - name: dpkg-divert --divert /usr/share/nginx/init.d --add /etc/init.d/nginx
  17. - require:
  18. - module: nginx-old-init
  19. - watch:
  20. - file: nginx-old-init
  21. - require_in:
  22. - file: nginx
  23. {% endif %}
  24. module.wait:
  25. - name: cmd.run
  26. - cmd: sh -c "kill `cat /var/run/nginx.pid`"
  27. - watch:
  28. - file: nginx-old-init
  29. - require_in:
  30. - file: nginx
  31. - onlyif: [ -e /var/run/nginx.pid ]
  32. # RedHat requires the init file in place to chkconfig off
  33. {% if nginx['disable_before_rename'] %}
  34. {% set _in = '_in' %}
  35. {% else %}
  36. {% set _in = '' %}
  37. {% endif %}
  38. nginx-old-init-disable:
  39. cmd.run:
  40. - name: {{ nginx.old_init_disable }}
  41. - require{{ _in }}:
  42. - module: nginx-old-init
  43. - onlyif: [ -f /etc/init.d/nginx ]
  44. {% endif %}
  45. {% if grains.get('os_family') == 'Debian' %}
  46. {% set repo_source = pillar.get('nginx', {}).get('repo_source', 'default') %}
  47. {% set use_ppa = repo_source == 'ppa' and grains.get('os') == 'Ubuntu' %}
  48. {% set use_official = repo_source == 'official' and grains.get('os') in ('Ubuntu', 'Debian') %}
  49. nginx-ppa-repo:
  50. pkgrepo:
  51. {%- if use_ppa %}
  52. - managed
  53. {%- else %}
  54. - absent
  55. {%- endif %}
  56. - humanname: nginx-ppa-{{ grains['oscodename'] }}
  57. - name: deb http://ppa.launchpad.net/nginx/{{ pillar.get('nginx', {}).get('repo_version', 'stable') }}/ubuntu {{ grains['oscodename'] }} main
  58. - file: /etc/apt/sources.list.d/nginx-{{ pillar.get('nginx', {}).get('repo_version', 'stable') }}-{{ grains['oscodename'] }}.list
  59. - dist: {{ grains['oscodename'] }}
  60. - keyid: C300EE8C
  61. - keyserver: keyserver.ubuntu.com
  62. - require_in:
  63. - pkg: nginx
  64. - watch_in:
  65. - pkg: nginx
  66. nginx-official-repo:
  67. pkgrepo:
  68. {%- if use_official %}
  69. - managed
  70. {%- else %}
  71. - absent
  72. {%- endif %}
  73. - humanname: nginx apt repo
  74. - name: deb http://nginx.org/packages/{{ grains['os'].lower() }}/ {{ grains['oscodename'] }} nginx
  75. - file: /etc/apt/sources.list.d/nginx-official-{{ grains['oscodename'] }}.list
  76. - keyid: ABF5BD827BD9BF62
  77. - keyserver: keyserver.ubuntu.com
  78. - require_in:
  79. - pkg: nginx
  80. - watch_in:
  81. - pkg: nginx
  82. {% endif %}
  83. nginx:
  84. pkg.installed:
  85. - name: {{ nginx.package }}
  86. {% if use_upstart %}
  87. file.managed:
  88. - name: /etc/init/nginx.conf
  89. - template: jinja
  90. - user: root
  91. - group: root
  92. - mode: 440
  93. - source: salt://nginx/templates/upstart.jinja
  94. - require:
  95. - pkg: nginx
  96. - file: nginx-old-init
  97. - module: nginx-old-init
  98. {% endif %}
  99. service.running:
  100. - enable: True
  101. - restart: True
  102. - watch:
  103. {% if use_upstart %}
  104. - file: nginx
  105. {% endif %}
  106. {% set conf_dir = salt['pillar.get']('nginx:conf_dir', '/etc/nginx') %}
  107. - file: {{ conf_dir }}/nginx.conf
  108. - file: {{ conf_dir }}/conf.d/default.conf
  109. - file: {{ conf_dir }}/conf.d/example_ssl.conf
  110. - pkg: nginx
  111. # Create 'service' symlink for tab completion.
  112. # This is not supported in os_family RedHat and likely only works in
  113. # Debian-based distros
  114. {% if use_upstart and grains['os_family'] == 'Debian' %}
  115. /etc/init.d/nginx:
  116. file.symlink:
  117. - target: /lib/init/upstart-job
  118. - force: True
  119. {% endif %}