Merge pull request #26 from lexfo/master
Allow managing logrotate defaults
This commit is contained in:
commit
74df45ba23
14 changed files with 190 additions and 202 deletions
|
@ -25,9 +25,17 @@ Installs the ``logrotate`` package and service/timer/cron.
|
|||
|
||||
Manages logrotate config and include dir.
|
||||
|
||||
``logrotate.install``
|
||||
---------------------
|
||||
|
||||
Installs the logrotate package and its dependencies.
|
||||
|
||||
``logrotate.jobs``
|
||||
------------------
|
||||
|
||||
Create custom job for logrotate.
|
||||
|
||||
``logrotate.service``
|
||||
---------------------
|
||||
|
||||
Manages the startup and running state of the logrotate service.
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
include:
|
||||
- logrotate
|
||||
|
||||
logrotate_config:
|
||||
logrotate-config:
|
||||
file.managed:
|
||||
- name: {{ logrotate.conf_file }}
|
||||
- source: salt://logrotate/files/{{ salt['grains.get']('os_family') }}/logrotate.conf
|
||||
- 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') }}
|
||||
- require:
|
||||
- pkg: logrotate
|
||||
|
||||
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
|
||||
- makedirs: True
|
||||
|
||||
|
|
16
logrotate/defaults.yaml
Normal file
16
logrotate/defaults.yaml
Normal file
|
@ -0,0 +1,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=yaml
|
||||
|
||||
logrotate:
|
||||
pkg: logrotate
|
||||
conf_file: '/etc/logrotate.conf'
|
||||
include_dir: '/etc/logrotate.d'
|
||||
user: root
|
||||
group: root
|
||||
service: cron
|
||||
login_records_jobs: True
|
||||
default_config:
|
||||
weekly: True
|
||||
rotate: 4
|
||||
create: True
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
# see "man logrotate" for details
|
||||
# rotate log files weekly
|
||||
weekly
|
||||
|
||||
# keep 4 weeks worth of backlogs
|
||||
rotate 4
|
||||
|
||||
# restrict maximum size of log files
|
||||
#size 20M
|
||||
|
||||
# create new (empty) log files after rotating old ones
|
||||
create
|
||||
|
||||
# uncomment this if you want your log files compressed
|
||||
#compress
|
||||
|
||||
# Logs are moved into directory for rotation
|
||||
# olddir /var/log/archive
|
||||
|
||||
# Ignore pacman saved files
|
||||
tabooext + .pacorig .pacnew .pacsave
|
||||
|
||||
# Arch packages drop log rotation information into this directory
|
||||
include /etc/logrotate.d
|
||||
|
||||
/var/log/wtmp {
|
||||
monthly
|
||||
create 0664 root utmp
|
||||
minsize 1M
|
||||
rotate 1
|
||||
}
|
||||
|
||||
/var/log/btmp {
|
||||
missingok
|
||||
monthly
|
||||
create 0600 root utmp
|
||||
rotate 1
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
# see "man logrotate" for details
|
||||
# rotate log files weekly
|
||||
weekly
|
||||
|
||||
{% if grains['os'] == "Ubuntu" %}
|
||||
# use the syslog group by default, since this is the owning group
|
||||
# of /var/log/syslog.
|
||||
su root syslog
|
||||
{% endif %}
|
||||
|
||||
# keep 4 weeks worth of backlogs
|
||||
rotate 4
|
||||
|
||||
# create new (empty) log files after rotating old ones
|
||||
create
|
||||
|
||||
# uncomment this if you want your log files compressed
|
||||
#compress
|
||||
|
||||
# packages drop log rotation information into this directory
|
||||
include /etc/logrotate.d
|
||||
|
||||
# no packages own wtmp, or btmp -- we'll rotate them here
|
||||
/var/log/wtmp {
|
||||
missingok
|
||||
monthly
|
||||
create 0664 root utmp
|
||||
rotate 1
|
||||
}
|
||||
|
||||
/var/log/btmp {
|
||||
missingok
|
||||
monthly
|
||||
create 0660 root utmp
|
||||
rotate 1
|
||||
}
|
||||
|
||||
# system-specific logs may be configured here
|
|
@ -1,35 +0,0 @@
|
|||
# see "man logrotate" for details
|
||||
# rotate log files weekly
|
||||
weekly
|
||||
|
||||
# keep 4 weeks worth of backlogs
|
||||
rotate 4
|
||||
|
||||
# create new (empty) log files after rotating old ones
|
||||
create
|
||||
|
||||
# use date as a suffix of the rotated file
|
||||
dateext
|
||||
|
||||
# uncomment this if you want your log files compressed
|
||||
#compress
|
||||
|
||||
# RPM packages drop log rotation information into this directory
|
||||
include /etc/logrotate.d
|
||||
|
||||
# no packages own wtmp and btmp -- we'll rotate them here
|
||||
/var/log/wtmp {
|
||||
monthly
|
||||
create 0664 root utmp
|
||||
minsize 1M
|
||||
rotate 1
|
||||
}
|
||||
|
||||
/var/log/btmp {
|
||||
missingok
|
||||
monthly
|
||||
create 0600 root utmp
|
||||
rotate 1
|
||||
}
|
||||
|
||||
# system-specific logs may be also be configured here.
|
|
@ -1,26 +0,0 @@
|
|||
# see "man logrotate" for details
|
||||
# rotate log files weekly
|
||||
weekly
|
||||
|
||||
# keep 4 weeks worth of backlogs
|
||||
rotate 4
|
||||
|
||||
# create new (empty) log files after rotating old ones
|
||||
create
|
||||
|
||||
# use date as a suffix of the rotated file
|
||||
dateext
|
||||
|
||||
# uncomment this if you want your log files compressed
|
||||
#compress
|
||||
|
||||
# comment these to switch compression to use gzip or another
|
||||
# compression scheme
|
||||
compresscmd /usr/bin/xz
|
||||
uncompresscmd /usr/bin/xzdec
|
||||
|
||||
# former versions had to have the compressext set accordingly
|
||||
#compressext .xz
|
||||
|
||||
# RPM packages drop log rotation information into this directory
|
||||
include /etc/logrotate.d
|
|
@ -1,19 +1,7 @@
|
|||
{% from "logrotate/map.jinja" import logrotate with context %}
|
||||
|
||||
logrotate:
|
||||
pkg.installed:
|
||||
- name: {{ logrotate.pkg|json }}
|
||||
service.running:
|
||||
- name: {{ logrotate.service }}
|
||||
- enable: True
|
||||
|
||||
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
|
||||
- makedirs: True
|
||||
- require:
|
||||
- pkg: logrotate
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
include:
|
||||
- logrotate.install
|
||||
- logrotate.config
|
||||
- logrotate.service
|
||||
|
|
8
logrotate/install.sls
Normal file
8
logrotate/install.sls
Normal file
|
@ -0,0 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
{% from "logrotate/map.jinja" import logrotate with context %}
|
||||
|
||||
logrotate-pkg:
|
||||
pkg.installed:
|
||||
- name: {{ logrotate.pkg }}
|
|
@ -5,8 +5,8 @@
|
|||
include:
|
||||
- logrotate
|
||||
|
||||
{% for key,value in jobs.items() %}
|
||||
logrotate_{{key}}:
|
||||
{% for key, value in jobs.items() %}
|
||||
logrotate-{{ key }}:
|
||||
file.managed:
|
||||
- name: {{ logrotate.include_dir }}/{{ key.split("/")[-1] }}
|
||||
- source: salt://logrotate/templates/job.tmpl
|
||||
|
@ -15,7 +15,7 @@ logrotate_{{key}}:
|
|||
- group: {{ salt['pillar.get']('logrotate:config:group', logrotate.group) }}
|
||||
- mode: {{ salt['pillar.get']('logrotate:config:mode', '644') }}
|
||||
- require:
|
||||
- pkg: logrotate
|
||||
- pkg: logrotate-pkg
|
||||
- context:
|
||||
{% if value is mapping %}
|
||||
path: {{ value.get('path', []) }}
|
||||
|
|
|
@ -1,42 +1,48 @@
|
|||
{% set logrotate = salt['grains.filter_by']({
|
||||
'RedHat': {
|
||||
'pkg' : 'logrotate',
|
||||
'service' : 'crond',
|
||||
'conf_file' : '/etc/logrotate.conf',
|
||||
'include_dir' : '/etc/logrotate.d',
|
||||
'user' : 'root',
|
||||
'group' : 'root',
|
||||
},
|
||||
'ScientificLinux': {
|
||||
'pkg' : 'logrotate',
|
||||
'service' : 'crond',
|
||||
'conf_file' : '/etc/logrotate.conf',
|
||||
'include_dir' : '/etc/logrotate.d',
|
||||
'user' : 'root',
|
||||
'group' : 'root',
|
||||
},
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=jinja
|
||||
|
||||
{% import_yaml 'logrotate/defaults.yaml' as default_settings %}
|
||||
|
||||
{% set os_family_map = salt['grains.filter_by']({
|
||||
'Arch': {
|
||||
'pkg' : 'logrotate',
|
||||
'service' : 'logrotate.timer',
|
||||
'conf_file' : '/etc/logrotate.conf',
|
||||
'include_dir' : '/etc/logrotate.d',
|
||||
'user' : 'root',
|
||||
'group' : 'root',
|
||||
'service': 'logrotate.timer',
|
||||
'default_config': {
|
||||
'tabooext': '+ .pacorig .pacnew .pacsave',
|
||||
},
|
||||
},
|
||||
'RedHat': {
|
||||
'service': 'crond',
|
||||
'default_config': {
|
||||
'dateext': True,
|
||||
},
|
||||
'Debian': {
|
||||
'pkg' : 'logrotate',
|
||||
'service' : 'cron',
|
||||
'conf_file' : '/etc/logrotate.conf',
|
||||
'include_dir' : '/etc/logrotate.d',
|
||||
'user' : 'root',
|
||||
'group' : 'root',
|
||||
},
|
||||
'Suse': {
|
||||
'pkg' : 'logrotate',
|
||||
'service' : 'cron',
|
||||
'conf_file' : '/etc/logrotate.conf',
|
||||
'include_dir' : '/etc/logrotate.d',
|
||||
'user' : 'root',
|
||||
'group' : 'root',
|
||||
'login_records_jobs': False,
|
||||
'default_config': {
|
||||
'dateext': True,
|
||||
'compresscmd': '/usr/bin/xz',
|
||||
'uncompresscmd': '/usr/bin/xzdec',
|
||||
},
|
||||
}, merge=salt['pillar.get']('logrotate:lookup')) %}
|
||||
},
|
||||
},
|
||||
grain="os_family",
|
||||
merge=salt['pillar.get']('logrotate:lookup')) or {}
|
||||
%}
|
||||
|
||||
{% set os_map = salt['grains.filter_by']({
|
||||
'Ubuntu': {
|
||||
'default_config': {
|
||||
'su': 'root syslog'
|
||||
},
|
||||
},
|
||||
},
|
||||
grain="os",
|
||||
merge=os_family_map) or {}
|
||||
%}
|
||||
|
||||
{% set logrotate = salt['grains.filter_by'](
|
||||
default_settings,
|
||||
merge=os_map,
|
||||
base='logrotate',
|
||||
)
|
||||
%}
|
||||
|
|
17
logrotate/service.sls
Normal file
17
logrotate/service.sls
Normal file
|
@ -0,0 +1,17 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vim: ft=sls
|
||||
|
||||
{% from "logrotate/map.jinja" import logrotate with context %}
|
||||
|
||||
include:
|
||||
- logrotate.config
|
||||
- logrotate.install
|
||||
|
||||
logrotate:
|
||||
service.running:
|
||||
- name: {{ logrotate.service }}
|
||||
- enable: True
|
||||
- require:
|
||||
- pkg: logrotate-pkg
|
||||
- file: logrotate-config
|
||||
- file: logrotate-directory
|
70
logrotate/templates/logrotate.conf.tmpl
Normal file
70
logrotate/templates/logrotate.conf.tmpl
Normal file
|
@ -0,0 +1,70 @@
|
|||
{%- from "logrotate/map.jinja" import logrotate with context -%}
|
||||
{%- set config = salt['pillar.get']('logrotate:default_config', logrotate.default_config) -%}
|
||||
|
||||
{%- set processed_parameters = [] -%}
|
||||
|
||||
{%- macro set_parameter(parameter, default=None) -%}
|
||||
{%- set value = config.get(parameter, default) -%}
|
||||
{%- if value is not none %}
|
||||
{%- if value is sameas true -%}
|
||||
{{ parameter }}
|
||||
{%- elif value is sameas false -%}
|
||||
no{{ parameter }}
|
||||
{%- elif value is string or value is number -%}
|
||||
{{ parameter }} {{ value }}
|
||||
{%- else -%}
|
||||
{{ value }}
|
||||
{%- endif %}
|
||||
{%- do processed_parameters.append(parameter) %}
|
||||
{%- endif %}
|
||||
{%- endmacro -%}
|
||||
|
||||
# Managed by saltstack
|
||||
#
|
||||
# See "man logrotate" for details.
|
||||
|
||||
# log files rotation period
|
||||
{% for period in ['hourly', 'daily', 'weekly', 'yearly'] -%}
|
||||
{{ set_parameter(period) }}
|
||||
{%- endfor %}
|
||||
|
||||
# keep x periods worth of backlogs
|
||||
{{ set_parameter('rotate', 4) }}
|
||||
|
||||
# create new (empty) log files after rotating old ones
|
||||
{{ set_parameter('create', True) }}
|
||||
|
||||
# use date as a suffix of the rotated file
|
||||
{{ set_parameter('dateext', False) }}
|
||||
|
||||
# change this if you want your log files compressed
|
||||
{{ set_parameter('compress', False) }}
|
||||
|
||||
{#- Accept arbitrary parameters #}
|
||||
{%- for parameter in config %}
|
||||
{%- if parameter not in processed_parameters %}
|
||||
{{ set_parameter(parameter) }}
|
||||
{%- endif %}
|
||||
{%- endfor %}
|
||||
|
||||
# packages drop log rotation information into this directory
|
||||
include {{ logrotate.include_dir }}
|
||||
|
||||
{% if logrotate.login_records_jobs -%}
|
||||
# no packages own wtmp and btmp -- we'll rotate them here
|
||||
/var/log/wtmp {
|
||||
monthly
|
||||
create 0664 root utmp
|
||||
minsize 1M
|
||||
rotate 1
|
||||
}
|
||||
|
||||
/var/log/btmp {
|
||||
missingok
|
||||
monthly
|
||||
create 0600 root utmp
|
||||
rotate 1
|
||||
}
|
||||
{%- endif %}
|
||||
|
||||
# system-specific logs may be configured here
|
|
@ -3,6 +3,12 @@ logrotate:
|
|||
lookup:
|
||||
pkg: logrotate
|
||||
service: crond
|
||||
default_config:
|
||||
weekly: True
|
||||
rotate: 52
|
||||
create: True
|
||||
compress: True
|
||||
dateext: True
|
||||
jobs:
|
||||
/tmp/var/log/mysql/error:
|
||||
config:
|
||||
|
|
Loading…
Reference in a new issue