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.

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