feat(hourly): add configuration to enable hourly jobs
This commit is contained in:
parent
da488f4bf7
commit
7b5676b9e2
5 changed files with 71 additions and 7 deletions
|
@ -3,22 +3,62 @@
|
||||||
include:
|
include:
|
||||||
- logrotate
|
- logrotate
|
||||||
|
|
||||||
|
{% set ns = namespace(hourly=False) %}
|
||||||
|
{% set jobs = salt['config.get']('logrotate:jobs', {}) %}
|
||||||
|
{% for key, value in logrotate.jobs.items() %}
|
||||||
|
{% set contents = value.get('contents', False) %}
|
||||||
|
{% if 'hourly' in (contents or value.config) %}
|
||||||
|
{% set ns.hourly = True %}
|
||||||
|
{% break %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
logrotate-config:
|
logrotate-config:
|
||||||
file.managed:
|
file.managed:
|
||||||
- name: {{ logrotate.conf_file }}
|
- name: {{ logrotate.conf_file }}
|
||||||
- source: salt://logrotate/templates/logrotate.conf.tmpl
|
- source: salt://logrotate/templates/logrotate.conf.tmpl
|
||||||
- template: jinja
|
- template: jinja
|
||||||
- user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }}
|
- user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
|
||||||
- group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }}
|
- group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
|
||||||
- mode: {{ salt['pillar.get']('logrotate:config:mode', '644') }}
|
- mode: {{ salt['config.get']('logrotate:config:mode', '0644') }}
|
||||||
- context:
|
- context:
|
||||||
logrotate: {{ logrotate|tojson }}
|
logrotate: {{ logrotate|tojson }}
|
||||||
|
|
||||||
logrotate-directory:
|
logrotate-directory:
|
||||||
file.directory:
|
file.directory:
|
||||||
- name: {{ logrotate.include_dir }}
|
- name: {{ logrotate.include_dir }}
|
||||||
- user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }}
|
- user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
|
||||||
- group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }}
|
- group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
|
||||||
- mode: 755
|
- mode: '0755'
|
||||||
- makedirs: True
|
- makedirs: True
|
||||||
|
|
||||||
|
{%- if ns.hourly %}
|
||||||
|
logrotate-hourly-config:
|
||||||
|
file.managed:
|
||||||
|
- name: {{ logrotate.hourly_conf_file }}
|
||||||
|
- user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
|
||||||
|
- group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
|
||||||
|
- mode: {{ salt['config.get']('logrotate:config:mode', '0644') }}
|
||||||
|
- contents:
|
||||||
|
- include {{ logrotate.hourly_include_dir }}
|
||||||
|
|
||||||
|
logrotate-hourly-directory:
|
||||||
|
file.directory:
|
||||||
|
- name: {{ logrotate.hourly_include_dir }}
|
||||||
|
- user: {{ logrotate.user }}
|
||||||
|
- group: {{ logrotate.group }}
|
||||||
|
- mode: '0755'
|
||||||
|
- makedirs: True
|
||||||
|
|
||||||
|
logrotate-hourly-cron:
|
||||||
|
file.managed:
|
||||||
|
- name: "/etc/cron.hourly/logrotate"
|
||||||
|
- source: salt://logrotate/templates/logrotate.hourly.tmpl
|
||||||
|
- template: jinja
|
||||||
|
- user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
|
||||||
|
- group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
|
||||||
|
- mode: '0775'
|
||||||
|
- context:
|
||||||
|
logrotate: {{ logrotate|tojson }}
|
||||||
|
|
||||||
|
{%- endif %}
|
||||||
|
|
|
@ -2,9 +2,13 @@
|
||||||
# vim: ft=yaml
|
# vim: ft=yaml
|
||||||
---
|
---
|
||||||
logrotate:
|
logrotate:
|
||||||
|
bin: /usr/sbin/logrotate
|
||||||
|
status_dir: /var/lib/logrotate
|
||||||
pkg: logrotate
|
pkg: logrotate
|
||||||
conf_file: '/etc/logrotate.conf'
|
conf_file: '/etc/logrotate.conf'
|
||||||
include_dir: '/etc/logrotate.d'
|
include_dir: '/etc/logrotate.d'
|
||||||
|
hourly_conf_file: '/etc/logrotate.hourly.conf'
|
||||||
|
hourly_include_dir: '/etc/logrotate.hourly.d'
|
||||||
user: root
|
user: root
|
||||||
group: root
|
group: root
|
||||||
service: cron
|
service: cron
|
||||||
|
|
|
@ -7,9 +7,16 @@ include:
|
||||||
|
|
||||||
{% for key, value in jobs.items() %}
|
{% for key, value in jobs.items() %}
|
||||||
{% set contents = value.get('contents', False) %}
|
{% set contents = value.get('contents', False) %}
|
||||||
|
|
||||||
logrotate-{{ key }}:
|
logrotate-{{ key }}:
|
||||||
file.managed:
|
file.managed:
|
||||||
|
{% if 'hourly' in (contents or value.config) %}
|
||||||
|
- name: {{ logrotate.hourly_include_dir }}/{{ key.split("/")[-1] }}
|
||||||
|
- require:
|
||||||
|
- file: {{ logrotate.hourly_include_dir }}
|
||||||
|
{% else %}
|
||||||
- name: {{ logrotate.include_dir }}/{{ key.split("/")[-1] }}
|
- name: {{ logrotate.include_dir }}/{{ key.split("/")[-1] }}
|
||||||
|
{% endif %}
|
||||||
- user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }}
|
- user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }}
|
||||||
- group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }}
|
- group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }}
|
||||||
- mode: {{ salt['pillar.get']('logrotate:config:mode', '644') }}
|
- mode: {{ salt['pillar.get']('logrotate:config:mode', '644') }}
|
||||||
|
@ -29,5 +36,5 @@ logrotate-{{ key }}:
|
||||||
data: {{ value | json }}
|
data: {{ value | json }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endfor -%}
|
|
||||||
|
|
||||||
|
{% endfor %}
|
||||||
|
|
|
@ -26,6 +26,10 @@ Gentoo:
|
||||||
tabooext: + .keep
|
tabooext: + .keep
|
||||||
dateext: true
|
dateext: true
|
||||||
FreeBSD:
|
FreeBSD:
|
||||||
|
bin: /usr/local/sbin/logrotate
|
||||||
|
status_dir: /var/run
|
||||||
conf_file: /usr/local/etc/logrotate.conf
|
conf_file: /usr/local/etc/logrotate.conf
|
||||||
|
hourly_conf_file: /usr/local/etc/logrotate.hourly.conf
|
||||||
include_dir: /usr/local/etc/logrotate.d
|
include_dir: /usr/local/etc/logrotate.d
|
||||||
|
hourly_include_dir: /usr/local/etc/logrotate.hourly.d
|
||||||
group: wheel
|
group: wheel
|
||||||
|
|
9
logrotate/templates/logrotate.hourly.tmpl
Normal file
9
logrotate/templates/logrotate.hourly.tmpl
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
{{ logrotate.bin }} -s {{ logrotate.status_dir }}/logrotate.hourly.status {{ logrotate.hourly_conf_file }}
|
||||||
|
EXITVALUE=$?
|
||||||
|
if [ $EXITVALUE != 0 ]; then
|
||||||
|
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in a new issue