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.

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