From 38808d62217f51a07192e7a112dedb49d820a225 Mon Sep 17 00:00:00 2001 From: Niels Abspoel Date: Thu, 1 Jan 2015 19:52:08 +0100 Subject: [PATCH] Initial commit to add all files --- LICENSE | 14 ++++++++++ README.rst | 23 ++++++++++++++++ logrotate/config.sls | 29 ++++++++++++++++++++ logrotate/files/Arch/logrotate.conf | 38 +++++++++++++++++++++++++++ logrotate/files/Debian/logrotate.conf | 32 ++++++++++++++++++++++ logrotate/files/RedHat/logrotate.conf | 35 ++++++++++++++++++++++++ logrotate/init.sls | 9 +++++++ logrotate/map.jinja | 26 ++++++++++++++++++ pillar.example | 1 + 9 files changed, 207 insertions(+) create mode 100644 LICENSE create mode 100644 README.rst create mode 100644 logrotate/config.sls create mode 100644 logrotate/files/Arch/logrotate.conf create mode 100644 logrotate/files/Debian/logrotate.conf create mode 100644 logrotate/files/RedHat/logrotate.conf create mode 100644 logrotate/init.sls create mode 100644 logrotate/map.jinja create mode 100644 pillar.example diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..47d69b9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,14 @@ + Copyright (c) 2013-2014 Salt Stack Formulas + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..89764ac --- /dev/null +++ b/README.rst @@ -0,0 +1,23 @@ +logrotate +========= +Install and configure logrotate on a machine. + +.. note:: + See the full `Salt Formulas installation and usage instructions + `_. + +Available states +================ + +.. contents:: + :local: + +``logrotate`` +------------- + +Installs the ``logrotate`` package and service/timer/cron. + +``logrotate.config`` +-------------------- + +Manages logrotate config and include dir. diff --git a/logrotate/config.sls b/logrotate/config.sls new file mode 100644 index 0000000..48cade5 --- /dev/null +++ b/logrotate/config.sls @@ -0,0 +1,29 @@ +{% from "logrotate/map.jinja" import logrotate with context %} + +include: + - 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 + - require: + - pkg: logrotate + +logrotate_config: + file.managed: + - name: {{ logrotate.conf_file }} + - source: salt://logrotate/files/{{ salt['grains.get']('os_family') }}/logrotate.conf + - 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 + - watch_in: + - service: {{ logrotate.service }} + + diff --git a/logrotate/files/Arch/logrotate.conf b/logrotate/files/Arch/logrotate.conf new file mode 100644 index 0000000..974f0f4 --- /dev/null +++ b/logrotate/files/Arch/logrotate.conf @@ -0,0 +1,38 @@ +# 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 +} diff --git a/logrotate/files/Debian/logrotate.conf b/logrotate/files/Debian/logrotate.conf new file mode 100644 index 0000000..4bd60ab --- /dev/null +++ b/logrotate/files/Debian/logrotate.conf @@ -0,0 +1,32 @@ +# 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 + +# 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 diff --git a/logrotate/files/RedHat/logrotate.conf b/logrotate/files/RedHat/logrotate.conf new file mode 100644 index 0000000..56e9103 --- /dev/null +++ b/logrotate/files/RedHat/logrotate.conf @@ -0,0 +1,35 @@ +# 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. diff --git a/logrotate/init.sls b/logrotate/init.sls new file mode 100644 index 0000000..6e3c5cd --- /dev/null +++ b/logrotate/init.sls @@ -0,0 +1,9 @@ +{% from "logrotate/map.jinja" import logrotate with context %} + +logrotate: + pkg.installed: + - name: {{ logrotate.pkg|json }} + service.running: + - name: {{ logrotate.service }} + - enable: True + - reload: True diff --git a/logrotate/map.jinja b/logrotate/map.jinja new file mode 100644 index 0000000..aa20abf --- /dev/null +++ b/logrotate/map.jinja @@ -0,0 +1,26 @@ +{% 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', + }, + 'Arch': { + 'pkg' : 'logrotate', + 'service' : 'logrotate.timer', + 'conf_file' : '/etc/logrotate.conf', + 'include_dir' : '/etc/logrotate.d', + 'user' : 'root', + 'group' : 'root', + }, + 'Debian': { + 'pkg' : 'logrotate', + 'service' : 'crond', + 'conf_file' : '/etc/logrotate.conf', + 'include_dir' : '/etc/logrotate.d', + 'user' : 'root', + 'group' : 'root', + }, +}, merge=salt['pillar.get']('logrotate:lookup')) %} diff --git a/pillar.example b/pillar.example new file mode 100644 index 0000000..7b9bb60 --- /dev/null +++ b/pillar.example @@ -0,0 +1 @@ +none at the moment