init.sls 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. # get loopback IPv6 for binding the webserver to it
  24. {% set node_config = salt['pillar.get']('node') %}
  25. {% set bind_ip = salt['ffho_net.get_primary_ip'](node_config, 'v6').ip %}
  26. # for each site
  27. {% for site in node_config.get('sites', []) %}
  28. # add webserver directory
  29. /srv/yanic/data/{{site}}:
  30. file.directory:
  31. - require:
  32. - file: /srv/yanic/data
  33. # add configuration file
  34. /srv/yanic/{{site}}.conf:
  35. file.managed:
  36. - source: salt://yanic/yanic.conf.tmpl
  37. - template: jinja
  38. - defaults:
  39. iface: "br-{{site}}"
  40. site: "{{site}}"
  41. webserver: "{{ "true" if loop.first else "false" }}"
  42. bind_ip: {{bind_ip}}
  43. influxdb: {{node_config.yanic.influxdb}}
  44. - require:
  45. - file: /srv/yanic/data/{{site}}
  46. # enable the yanic service
  47. # and restart if configuration or binary has changed
  48. yanic@{{site}}:
  49. service.running:
  50. - enable: True
  51. - require:
  52. - file: /srv/yanic/{{site}}.conf
  53. - file: /etc/systemd/system/yanic@.service
  54. - watch:
  55. - file: /srv/yanic/{{site}}.conf
  56. - file: yanic
  57. {% endfor %}
  58. /usr/local/bin/ff_merge_nodes_json:
  59. file.managed:
  60. - source: salt://yanic/ff_merge_nodes_json
  61. - mode: 755
  62. /etc/cron.d/ff_merge_nodes_json:
  63. file.managed:
  64. - source: salt://yanic/ff_merge_nodes_json.cron
  65. # backup yanic data
  66. /srv/yanic/backup.sh:
  67. file.managed:
  68. - contents: |
  69. #!/bin/bash
  70. YANIC=/srv/yanic
  71. DATE=$(/bin/date +%Y%m%d-%H%M)
  72. BACKUP=${YANIC}/backup
  73. DAYS=7
  74. mkdir -p ${BACKUP}/${DATE}
  75. cp ${YANIC}/*.state ${BACKUP}/${DATE}
  76. find ${BACKUP} -mindepth 1 -mtime +${DAYS} -delete
  77. - mode: 755
  78. - user: root
  79. cron-yanic-backup:
  80. cron.present:
  81. - identifier: CRON_YANIC_BACKUP
  82. - user: root
  83. - name: /srv/yanic/backup.sh
  84. - minute: 0
  85. - hour: "*/12"