From dfc94e4fd9161bed881b8b134cb77c7acc02a28c Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 7 Feb 2018 10:28:02 +1100 Subject: [PATCH] Fix up log rotation Turns out this is a bit of a pain, and we found out via a full disk. Firstly, carbon wants to rotate it's own log files, but doesn't compress or cleanup. Disable this with ENABLE_LOGROTATION=False, which has been around for a while. This is copied from the upstream example config. Secondly, we were missing the console.log file. Change the rotate to just one for "*.log", and also add "sharedscripts" so the post-rotate is only run once per rotation of all files. Thirdly, copytruncate doesn't work [2]. It needs to be "nocreate"; the file is moved and carbon starts a new one (as suggested by the config comment). This is updated in the combined rotate section. [1] https://github.com/graphite-project/carbon/pull/68 [2] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=733856 Change-Id: I946bb728971db79a2f4d08f2787c0768b958fb53 --- manifests/init.pp | 29 ++++------------------------- spec/acceptance/basic_spec.rb | 12 ++---------- templates/carbon.conf.erb | 4 ++++ 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 83180e9..71518ec 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -176,37 +176,16 @@ class graphite( } include ::logrotate - logrotate::file { 'querylog': - log => '/var/log/graphite/carbon-cache-a/query.log', + logrotate::file { 'graphite-carbon': + log => '/var/log/graphite/carbon-cache-a/*.log', options => [ 'compress', - 'copytruncate', - 'missingok', - 'rotate 7', - 'daily', - 'notifempty', - ], - } - logrotate::file { 'listenerlog': - log => '/var/log/graphite/carbon-cache-a/listener.log', - options => [ - 'compress', - 'copytruncate', - 'missingok', - 'rotate 7', - 'daily', - 'notifempty', - ], - } - logrotate::file { 'createslog': - log => '/var/log/graphite/carbon-cache-a/creates.log', - options => [ - 'compress', - 'copytruncate', + 'nocreate', 'missingok', 'rotate 7', 'daily', 'notifempty', + 'sharedscripts', ], } diff --git a/spec/acceptance/basic_spec.rb b/spec/acceptance/basic_spec.rb index 4c096c6..2a84139 100644 --- a/spec/acceptance/basic_spec.rb +++ b/spec/acceptance/basic_spec.rb @@ -71,16 +71,8 @@ describe 'puppet-graphite module', :if => ['debian', 'ubuntu'].include?(os[:fami end end - describe file('/etc/logrotate.d/querylog') do - its(:content) { should include '/var/log/graphite/carbon-cache-a/query.log' } - end - - describe file('/etc/logrotate.d/listenerlog') do - its(:content) { should include '/var/log/graphite/carbon-cache-a/listener.log' } - end - - describe file('/etc/logrotate.d/createslog') do - its(:content) { should include '/var/log/graphite/carbon-cache-a/creates.log' } + describe file('/etc/logrotate.d/graphite-carbon') do + its(:content) { should include '/var/log/graphite/carbon-cache-a/*.log' } end describe file('/etc/statsd/config.js') do diff --git a/templates/carbon.conf.erb b/templates/carbon.conf.erb index 3256acc..8d5a9a3 100644 --- a/templates/carbon.conf.erb +++ b/templates/carbon.conf.erb @@ -31,6 +31,10 @@ LOCAL_DATA_DIR = /var/lib/graphite/storage/whisper/ # #LOCAL_DATA_DIR = /opt/graphite/storage/whisper/ +# Enable daily log rotation. If disabled, a new file will be opened whenever the log file path no +# longer exists (i.e. it is removed or renamed) +ENABLE_LOGROTATION = False + # Specify the user to drop privileges to # If this is blank carbon runs as the user that invokes it # This user must have write access to the local data directory