From 7c3997b8b9a87d3d267a46d165a135bac3a2f251 Mon Sep 17 00:00:00 2001 From: Swann Croiset Date: Mon, 24 Oct 2016 16:54:07 +0200 Subject: [PATCH] Configure logrotate for WSGI logs Change-Id: I1f0692d85c24687d3a51ee09ce082e3544fd7317 Closes-Bug: #1635222 --- .../puppet/modules/nagios/manifests/cgi.pp | 20 ++++++++++++++++- .../apache_wsgi_vhost_ubuntu.conf.erb | 4 ++-- .../nagios/templates/logrotate.conf.erb | 22 +++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 deployment_scripts/puppet/modules/nagios/templates/logrotate.conf.erb diff --git a/deployment_scripts/puppet/modules/nagios/manifests/cgi.pp b/deployment_scripts/puppet/modules/nagios/manifests/cgi.pp index 1341afa..4976c86 100644 --- a/deployment_scripts/puppet/modules/nagios/manifests/cgi.pp +++ b/deployment_scripts/puppet/modules/nagios/manifests/cgi.pp @@ -133,16 +133,34 @@ class nagios::cgi ( apache::custom_config { 'nagios-ui': content => template("nagios/${nagios::params::apache_ui_vhost_config_tpl}"), verify_command => $verify_command, + notify => Class['apache::service'], require => Class['apache'], } if $wsgi_vhost_listen_ip { + $log_dir = "${nagios::params::data_dir}/log" + file { $log_dir: + ensure => directory, + mode => '0650', + require => Class['apache'], + notify => Class['apache::service'], + } + $logrotate_conf = '/etc/logrotate.d/nagios_wsgi.conf' + file { $logrotate_conf: + ensure => present, + content => template('nagios/logrotate.conf.erb'), + owner => 'root', + group => 'root', + mode => '0644', + require => File[$log_dir], + } # Template uses these variables: cgi_htpasswd_file # nagios_command_file, wsgi_vhost_listen_ip, wsgi_processes, wsgi_threads, # wsgi_process_service_checks_script, wsgi_process_service_checks_location + # log_dir apache::custom_config { 'nagios-wsgi': content => template("nagios/${nagios::params::apache_wsgi_vhost_config_tpl}"), verify_command => $verify_command, - require => Class['apache'], + require => [Class['apache'], File[$log_dir]], } file { 'wsgi_process_service_checks_script': ensure => present, diff --git a/deployment_scripts/puppet/modules/nagios/templates/apache_wsgi_vhost_ubuntu.conf.erb b/deployment_scripts/puppet/modules/nagios/templates/apache_wsgi_vhost_ubuntu.conf.erb index e72d7b8..d85062c 100644 --- a/deployment_scripts/puppet/modules/nagios/templates/apache_wsgi_vhost_ubuntu.conf.erb +++ b/deployment_scripts/puppet/modules/nagios/templates/apache_wsgi_vhost_ubuntu.conf.erb @@ -25,7 +25,7 @@ require valid-user - ErrorLog "/var/log/apache2/nagios_wsgi_error.log" + ErrorLog "<%= @log_dir %>/nagios_wsgi_error.log" ServerSignature Off - CustomLog "/var/log/apache2/nagios_wsgi_access.log" combined + CustomLog "<%= @log_dir %>/nagios_wsgi_access.log" combined diff --git a/deployment_scripts/puppet/modules/nagios/templates/logrotate.conf.erb b/deployment_scripts/puppet/modules/nagios/templates/logrotate.conf.erb new file mode 100644 index 0000000..abb7038 --- /dev/null +++ b/deployment_scripts/puppet/modules/nagios/templates/logrotate.conf.erb @@ -0,0 +1,22 @@ +# managed by puppet +<%= @log_dir %>/*.log { + # use the copytruncate option to avoid restarting Apache + copytruncate + compress + delaycompress + missingok + notifempty + # logrotate allows to use only year, month, day and unix epoch + dateext + dateformat -%Y%m%d-%s + # number of rotated files to keep + rotate 10 + # do not rotate files unless both size and time conditions are met + hourly + minsize 20M + # force rotate if filesize exceeded 100M + maxsize 100M + # this must map the /var/log directory group ownership + su root syslog +} +