From 6fd3b90b696fc0e8e466973e20eb6bd7a83ab2f2 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Thu, 14 Mar 2019 14:16:02 +0100 Subject: [PATCH] Add cron script to compress and clean up logs on syslog hosts --- modules/syslog_ng/files/loggers-cron | 19 +++++++++++++++++++ modules/syslog_ng/manifests/init.pp | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 modules/syslog_ng/files/loggers-cron diff --git a/modules/syslog_ng/files/loggers-cron b/modules/syslog_ng/files/loggers-cron new file mode 100644 index 000000000..bdeee76d8 --- /dev/null +++ b/modules/syslog_ng/files/loggers-cron @@ -0,0 +1,19 @@ +#!/bin/bash + +# DO NOT MODIFY +# This file is maintained in dsa-puppet + +( + if ! flock -x -n 200 ; then exit; fi + + if [ "$1" = "-v" ]; then + verbose="-v" + else + verbose="" + fi + cpus=$(cat /proc/cpuinfo | grep '^processor[[:space:]]' | wc -l) + + find /var/log/hosts -type f ! -name '*.gz' -a ! -name '*.xz' -mtime +2 -print0 | xargs --no-run-if-empty -0 -n 4 -P "$cpus" xz $verbose + find /var/log/hosts -type f -mtime +50 -print0 | xargs --no-run-if-empty -0 rm $verbose + find /var/log/hosts -type d -mtime +2 -empty -print0 | xargs --no-run-if-empty -0 rmdir $verbose +) 200< /var/log/hosts diff --git a/modules/syslog_ng/manifests/init.pp b/modules/syslog_ng/manifests/init.pp index ead0954d5..3489fb474 100644 --- a/modules/syslog_ng/manifests/init.pp +++ b/modules/syslog_ng/manifests/init.pp @@ -28,6 +28,13 @@ class syslog_ng { source => 'puppet:///modules/syslog_ng/syslog-ng.logrotate.loggers', require => Package['syslog-ng'] } + file { '/etc/cron.daily/local-handle-loghost-logs': + ensure => absent, + } + file { '/etc/cron.daily/puppet-handle-loghost-logs': + source => 'puppet:///modules/syslog_ng/loggers-cron', + mode => '0555', + } } # while syslog-ng breaks on boot -- 2.20.1