init.sls 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. influxdb: {{node_config.yanic.influxdb}}
  46. # the webserver should only be enabled once
  47. {% set webserver = "false" %}
  48. - require:
  49. - file: /srv/yanic/data/{{site}}
  50. # enable the yanic service
  51. # and restart if configuration or binary has changed
  52. yanic@{{site}}:
  53. service.running:
  54. - enable: True
  55. - require:
  56. - file: /srv/yanic/{{site}}.conf
  57. - file: /etc/systemd/system/yanic@.service
  58. - watch:
  59. - file: /srv/yanic/{{site}}.conf
  60. - file: yanic
  61. {% endfor %}