init.sls 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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_primary_ip'](node_config, 'v6').ip %}
  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 %}
  62. /usr/local/bin/ff_merge_nodes_json:
  63. file.managed:
  64. - source: salt://yanic/ff_merge_nodes_json
  65. - mode: 755
  66. /etc/cron.d/ff_merge_nodes_json:
  67. file.managed:
  68. - source: salt://yanic/ff_merge_nodes_json.cron
  69. # backup yanic data
  70. /srv/yanic/backup.sh:
  71. file.managed:
  72. - contents: |
  73. #!/bin/bash
  74. YANIC=/srv/yanic
  75. DATE=$(/bin/date +%Y%m%d-%H%M)
  76. BACKUP=${YANIC}/backup
  77. DAYS=7
  78. mkdir -p ${BACKUP}/${DATE}
  79. cp ${YANIC}/*.state ${BACKUP}/${DATE}
  80. find ${BACKUP} -mindepth 1 -mtime +${DAYS} -delete
  81. - mode: 755
  82. - user: root
  83. cron-yanic-backup:
  84. cron.present:
  85. - identifier: CRON_YANIC_BACKUP
  86. - user: root
  87. - name: /srv/yanic/backup.sh
  88. - minute: 0
  89. - hour: "*/12"