From: Frank Brehm Date: Tue, 22 Mar 2016 19:44:48 +0000 (+0100) Subject: Adding state for logrotate package X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=85809b71698dac794281adcde787ac7b6556a3f5;p=salt%2Fstates.git Adding state for logrotate package --- diff --git a/basic/files/logrotate.conf b/basic/files/logrotate.conf new file mode 100644 index 0000000..b504c76 --- /dev/null +++ b/basic/files/logrotate.conf @@ -0,0 +1,35 @@ +# see "man logrotate" for details +# rotate log files weekly +weekly + +# keep 4 weeks worth of backlogs +rotate 99 + +# create new (empty) log files after rotating old ones +create + +# uncomment this if you want your log files compressed +compress +delaycompress + +# 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 12 + size 4M +} + +/var/log/btmp { + missingok + monthly + create 0660 root utmp + rotate 12 + size 4M +} + +# system-specific logs may be configured here diff --git a/basic/files/logrotate.cron b/basic/files/logrotate.cron new file mode 100755 index 0000000..1b7acd3 --- /dev/null +++ b/basic/files/logrotate.cron @@ -0,0 +1,14 @@ +#!/bin/bash + +{% set logrotate_verbose = salt['pillar.get']('logrotate:verbose', False) -%} +{%- set verbose_option = '' -%} +{%- if logrotate_verbose -%} + {%- set verbose_option = '-v' -%} +{%- endif -%} +test -x /usr/sbin/logrotate || exit 0 +LOG=/var/log/logrotate.log +echo >> ${LOG} +echo "################################################" >> ${LOG} +echo "[$(date --rfc-3339=seconds )]: Start Logrotating" >> ${LOG} +/usr/sbin/logrotate {{ verbose_option }} /etc/logrotate.conf 2>&1 >>${LOG} +echo "[$(date --rfc-3339=seconds )]: End Logrotating" >> ${LOG} diff --git a/basic/logrotate.sls b/basic/logrotate.sls new file mode 100644 index 0000000..489cf29 --- /dev/null +++ b/basic/logrotate.sls @@ -0,0 +1,36 @@ + +logrotate: + pkg: + - installed + +/etc/logrotate.d: + file.directory: + - user: root + - group: root + - dir_mode: 755 + +/etc/logrotate.conf: + file.managed: + - user: root + - group: root + - mode: 644 + - source: salt://basic/files/logrotate.conf + - backup: minion + - require: + - pkg: logrotate + - file: /etc/logrotate.d + +/etc/cron.daily/logrotate: + file.managed: + - user: root + - group: root + - mode: 755 + - source: salt://basic/files/logrotate.cron + - template: jinja + - backup: minion + - onlyif: + - test -d /etc/cron.daily + - require: + - pkg: logrotate + - file: /etc/logrotate.conf + diff --git a/top.sls b/top.sls index ecd4d2d..31c27f7 100644 --- a/top.sls +++ b/top.sls @@ -6,6 +6,7 @@ base: - basic.editors - basic.localization - debian.sysvinit + - basic.logrotate - basic.pkgs - basic.rsyslog - basic.shells