init.sls 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #
  2. # yanic
  3. #
  4. # add yanic directory
  5. /srv/yanic/data:
  6. file.directory:
  7. - makedirs: True
  8. # copy yanic binary to destination
  9. # the binary needs to be provided by the salt-master
  10. yanic:
  11. file.managed:
  12. - name: /srv/yanic/yanic
  13. - source: salt://yanic/yanic
  14. - mode: 755
  15. - require:
  16. - file: /srv/yanic/data
  17. # copy systemd yanic@.service
  18. /etc/systemd/system/yanic@.service:
  19. file.managed:
  20. - source: salt://yanic/yanic@.service
  21. - require:
  22. - file: yanic
  23. # the internal webserver should be enabled
  24. {% set webserver = "true" %}
  25. # get loopback IPv6 for binding the webserver to it
  26. {% set node_config = salt['pillar.get']('nodes:' ~ grains['id']) %}
  27. {% set bind_ip = salt['ffho_net.get_loopback_ip'](node_config, grains['id'], 'v6') %}
  28. # for each site
  29. {% for site in salt['pillar.get']('nodes:' ~ grains['id'] ~ ':sites', []) %}
  30. # add webserver directory
  31. /srv/yanic/data/{{site}}:
  32. file.directory:
  33. - require:
  34. - file: /srv/yanic/data
  35. # add configuration file
  36. /srv/yanic/{{site}}.conf:
  37. file.managed:
  38. - source: salt://yanic/yanic.conf.tmpl
  39. - template: jinja
  40. - defaults:
  41. iface: "br-{{site}}"
  42. site: "{{site}}"
  43. webserver: "{{webserver}}"
  44. bind_ip: {{bind_ip}}
  45. # the webserver should only be enabled once
  46. {% set webserver = "false" %}
  47. - require:
  48. - file: /srv/yanic/data/{{site}}
  49. # enable the yanic service
  50. # and restart if configuration or binary has changed
  51. yanic@{{site}}:
  52. service.running:
  53. - enable: True
  54. - require:
  55. - file: /srv/yanic/{{site}}.conf
  56. - file: /etc/systemd/system/yanic@.service
  57. - watch:
  58. - file: /srv/yanic/{{site}}.conf
  59. - file: yanic
  60. {% endfor %}