Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
salt-formulas
mirror
Logrotate Formula
Commits
7b5676b9
Unverified
Commit
7b5676b9
authored
Nov 23, 2021
by
Michael Schmitt
Browse files
feat(hourly): add configuration to enable hourly jobs
parent
da488f4b
Changes
5
Hide whitespace changes
Inline
Side-by-side
logrotate/config.sls
View file @
7b5676b9
...
...
@@ -3,22 +3,62 @@
include:
- 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:
file.managed:
- name: {{ logrotate.conf_file }}
- source: salt://logrotate/templates/logrotate.conf.tmpl
- template: jinja
- user: {{ salt['
pillar
.get']('logrotate:config:user', logrotate.user) }}
- group: {{ salt['
pillar
.get']('logrotate:config:group', logrotate.group) }}
- mode: {{ salt['
pillar
.get']('logrotate:config:mode', '644') }}
- 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', '
0
644') }}
- context:
logrotate: {{ logrotate|tojson }}
logrotate-directory:
file.directory:
- name: {{ logrotate.include_dir }}
- user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }}
- group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }}
- mode: 755
- user: {{ salt['config.get']('logrotate:config:user', logrotate.user) }}
- group: {{ salt['config.get']('logrotate:config:group', logrotate.group) }}
- mode: '0755'
- 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 %}
logrotate/defaults.yaml
View file @
7b5676b9
...
...
@@ -2,9 +2,13 @@
# vim: ft=yaml
---
logrotate
:
bin
:
/usr/sbin/logrotate
status_dir
:
/var/lib/logrotate
pkg
:
logrotate
conf_file
:
'
/etc/logrotate.conf'
include_dir
:
'
/etc/logrotate.d'
hourly_conf_file
:
'
/etc/logrotate.hourly.conf'
hourly_include_dir
:
'
/etc/logrotate.hourly.d'
user
:
root
group
:
root
service
:
cron
...
...
logrotate/jobs.sls
View file @
7b5676b9
...
...
@@ -7,9 +7,16 @@ include:
{% for key, value in jobs.items() %}
{% set contents = value.get('contents', False) %}
logrotate-{{ key }}:
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] }}
{% endif %}
- user: {{ salt['pillar.get']('logrotate:config:user', logrotate.user) }}
- group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }}
- mode: {{ salt['pillar.get']('logrotate:config:mode', '644') }}
...
...
@@ -29,5 +36,5 @@ logrotate-{{ key }}:
data: {{ value | json }}
{% endif %}
{% endif %}
{%- endfor -%}
{% endfor %}
logrotate/osfamilymap.yaml
View file @
7b5676b9
...
...
@@ -26,6 +26,10 @@ Gentoo:
tabooext
:
+ .keep
dateext
:
true
FreeBSD
:
bin
:
/usr/local/sbin/logrotate
status_dir
:
/var/run
conf_file
:
/usr/local/etc/logrotate.conf
hourly_conf_file
:
/usr/local/etc/logrotate.hourly.conf
include_dir
:
/usr/local/etc/logrotate.d
hourly_include_dir
:
/usr/local/etc/logrotate.hourly.d
group
:
wheel
logrotate/templates/logrotate.hourly.tmpl
0 → 100644
View file @
7b5676b9
#!/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
Francesco Gionghi
@fgionghi
mentioned in commit
726d537f
·
Feb 28, 2022
mentioned in commit
726d537f
mentioned in commit 726d537f9ae05361b8a74e73076443c99af0e51b
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment