Saltstack Official Logrotate Formula
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

64 行
2.0KB

  1. {% from "logrotate/map.jinja" import logrotate with context %}
  2. include:
  3. - logrotate
  4. {% set ns = namespace(hourly=False) %}
  5. {% for key, value in logrotate.jobs.items() %}
  6. {% set contents = value.get('contents', False) %}
  7. {% if 'hourly' in (contents or value.config) %}
  8. {% set ns.hourly = True %}
  9. {% break %}
  10. {% endif %}
  11. {% endfor %}
  12. logrotate-config:
  13. file.managed:
  14. - name: {{ logrotate.conf_file }}
  15. - source: salt://logrotate/templates/logrotate.conf.tmpl
  16. - template: jinja
  17. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  18. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  19. - mode: {{ salt['config.get']('logrotate:config:mode', '0644') }}
  20. - context:
  21. logrotate: {{ logrotate|tojson }}
  22. logrotate-directory:
  23. file.directory:
  24. - name: {{ logrotate.include_dir }}
  25. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  26. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  27. - mode: '0755'
  28. - makedirs: True
  29. {%- if ns.hourly %}
  30. logrotate-hourly-config:
  31. file.managed:
  32. - name: {{ logrotate.hourly_conf_file }}
  33. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  34. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  35. - mode: {{ salt['config.get']('logrotate:config:mode', '0644') }}
  36. - contents:
  37. - include {{ logrotate.hourly_include_dir }}
  38. logrotate-hourly-directory:
  39. file.directory:
  40. - name: {{ logrotate.hourly_include_dir }}
  41. - user: {{ logrotate.user }}
  42. - group: {{ logrotate.group }}
  43. - mode: '0755'
  44. - makedirs: True
  45. logrotate-hourly-cron:
  46. file.managed:
  47. - name: "/etc/cron.hourly/logrotate"
  48. - source: salt://logrotate/templates/logrotate.hourly.tmpl
  49. - template: jinja
  50. - user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
  51. - group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
  52. - mode: '0775'
  53. - context:
  54. logrotate: {{ logrotate|tojson }}
  55. {%- endif %}