Logrotate cookbook - how to set option "olddir" per app


#1

Hi

We’re using the Logrotate Cookbook from Supermarket on Ubuntu 14.04, and it works quite well.

One question - for an application (Apache), I’d like to set the “olddir” option. How would I go about this? At the moment, I’ve got the following code in a recipe:

# Logrotate
logrotate_app 'apache-' + instance_name do
    path [node['apache']['instances'][instance_name]['log_path'] + "/" + node['apache']['instances'][instance_name]['error_log'], node['apache']['instances'][instance_name]['log_path'] + "/" + node['apache']['instances'][instance_name]['forwarded_log'], node['apache']['instances'][instance_name]['log_path'] + "/" + node['apache']['instances'][instance_name]['common_log'], node['apache']['instances'][instance_name]['log_path'] + "/" + node['apache']['instances'][instance_name]['access_log']]
    options ['missingok', 'compress', 'delaycompress', 'notifempty', 'sharedscripts']
    frequency 'weekly'
    create '644 root adm'
    rotate 52
    postrotate <<-EOFpostrotateapache2
        if /etc/init.d/apache2 status > /dev/null ; then \\
            /etc/init.d/apache2 reload > /dev/null; \\
        fi;
    EOFpostrotateapache2
    prerotate <<-EOFprerotateapache2
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \\
            run-parts /etc/logrotate.d/httpd-prerotate; \\
        fi;
    EOFprerotateapache2
end # of logrotate_app 'apache-' + instance_name do

This generated the following content in file /etc/logrotate.d/apache-mgmt:

# This file was generated by Chef for mgmt02-test.internal.
# Do not modify this file by hand!

"/srv/logs/apache/mgmt/mgmt.mgmt02-test.error_log" "/srv/logs/apache/mgmt/mgmt.mgmt02-test.forwarded_log" "/srv/logs/apache/mgmt/mgmt.mgmt02-test.common_log" "/srv/logs/apache/mgmt/mgmt.mgmt02-test.access_log" {
  weekly
  create 644 root adm
  rotate 52
  missingok
  compress
  delaycompress
  notifempty
  sharedscripts
  prerotate
          if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi;

  endscript
  postrotate
          if /etc/init.d/apache2 status > /dev/null ; then \
            /etc/init.d/apache2 reload > /dev/null; \
        fi;

  endscript
}

Now I’d need to add the “olddir” option there, because the customer wants to have rotated files in some directory. Ie., it should look like this:

# This file was generated by Chef for mgmt02-test.internal.
# Do not modify this file by hand!

"/srv/logs/apache/mgmt/mgmt.mgmt02-test.error_log" "/srv/logs/apache/mgmt/mgmt.mgmt02-test.forwarded_log" "/srv/logs/apache/mgmt/mgmt.mgmt02-test.common_log" "/srv/logs/apache/mgmt/mgmt.mgmt02-test.access_log" {
  olddir transfers
  
  weekly
  create 644 root adm
  rotate 52
  missingok
  compress
  delaycompress
  notifempty
  sharedscripts
  prerotate
          if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi;

  endscript
  postrotate
          if /etc/init.d/apache2 status > /dev/null ; then \
            /etc/init.d/apache2 reload > /dev/null; \
        fi;

  endscript
}

How can I do that? This did not work:

…
   options ['missingok', 'compress', 'delaycompress', 'notifempty', 'sharedscripts', 'olddir']

Chef stopped, because “olddir” was not a supported option.

Thanks a lot for your help,
Alexander


#2

Hi

I got an offlist reply with the solution:

logrotate_app "foo" do
  olddir "value"
end

It was really THAT easy :slightly_smiling: - sorry for having bothered G

Cheers,
Alexander


#3

You didn’t bother. That doesn’t seem to be documented very well for the
cookbook.

You can see in


that there are a bunch of parameters defined in the VALUES array which are
default logrotate options but are not documented in the README.md page.

If you wanted to help out the next people coming along then you might want
to considering making a pull request for that cookbook which updates the
documentation to say the logrotate.conf options can be set as parameters to
the resource in addition to the documented ones