]> Frank Brehm's Git Trees - salt/states.git/commitdiff
Adding state for logrotate package
authorFrank Brehm <frank@brehm-online.com>
Tue, 22 Mar 2016 19:44:48 +0000 (20:44 +0100)
committerFrank Brehm <frank@brehm-online.com>
Tue, 22 Mar 2016 19:44:48 +0000 (20:44 +0100)
basic/files/logrotate.conf [new file with mode: 0644]
basic/files/logrotate.cron [new file with mode: 0755]
basic/logrotate.sls [new file with mode: 0644]
top.sls

diff --git a/basic/files/logrotate.conf b/basic/files/logrotate.conf
new file mode 100644 (file)
index 0000000..b504c76
--- /dev/null
@@ -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 (executable)
index 0000000..1b7acd3
--- /dev/null
@@ -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 (file)
index 0000000..489cf29
--- /dev/null
@@ -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 ecd4d2d39509f625b52c6138137ecc0f4f765027..31c27f78f1ff23fb845b5ce7095b66569254939e 100644 (file)
--- 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