GithubHelp home page GithubHelp logo

sous-chefs / logrotate Goto Github PK

View Code? Open in Web Editor NEW
122.0 27.0 152.0 355 KB

Development repository for the logrotate cookbook

Home Page: https://supermarket.chef.io/cookbooks/logrotate

License: Apache License 2.0

Ruby 89.64% HTML 10.07% Shell 0.29%
chef hacktoberfest chef-cookbook logrotate chef-resource managed-by-terraform

logrotate's Introduction

logrotate Cookbook

Cookbook Version CI State OpenCollective OpenCollective License

Manages the logrotate package and provides a resource to manage application specific logrotate configuration.

Maintainers

This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.

Requirements

Platforms

Should work on any platform that includes a 'logrotate' package and writes logrotate configuration to /etc/logrotate.d.

Tested on:

  • Ubuntu / Debian
  • CentOS
  • Amazon Linux
  • openSUSE Leap

Chef

  • Chef 12.5+

Resources

Usage

The package resource will ensure logrotate is always up to date by default.

To create application specific logrotate configs, use the logrotate_app resource. For example, to rotate logs for a tomcat application named myapp that writes its log file to /var/log/tomcat/myapp.log:

logrotate_app 'tomcat-myapp' do
  path      '/var/log/tomcat/myapp.log'
  frequency 'daily'
  rotate    30
  create    '644 root adm'
end

To rotate multiple logfile paths, specify the path as an array:

logrotate_app 'tomcat-myapp' do
  path      ['/var/log/tomcat/myapp.log', '/opt/local/tomcat/catalina.out']
  frequency 'daily'
  create    '644 root adm'
  rotate    7
end

To specify which logrotate options, specify the options as an array:

logrotate_app 'tomcat-myapp' do
  path      '/var/log/tomcat/myapp.log'
  options   ['missingok', 'delaycompress', 'notifempty']
  frequency 'daily'
  rotate    30
  create    '644 root adm'
end

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers!

https://opencollective.com/sous-chefs#backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

https://opencollective.com/sous-chefs/sponsor/0/website https://opencollective.com/sous-chefs/sponsor/1/website https://opencollective.com/sous-chefs/sponsor/2/website https://opencollective.com/sous-chefs/sponsor/3/website https://opencollective.com/sous-chefs/sponsor/4/website https://opencollective.com/sous-chefs/sponsor/5/website https://opencollective.com/sous-chefs/sponsor/6/website https://opencollective.com/sous-chefs/sponsor/7/website https://opencollective.com/sous-chefs/sponsor/8/website https://opencollective.com/sous-chefs/sponsor/9/website

logrotate's People

Contributors

agperson avatar bmhughes avatar bodgix avatar colby avatar damacus avatar gregsymons avatar guilhem avatar jamesbelchamber avatar jannikolai avatar jasonwbarnett avatar jeffbyrnes avatar jschneiderhan avatar jwitrick avatar kitchen-porter avatar meineerde avatar mgalkiewicz avatar nathenharvey avatar nestorsalceda avatar ramereth avatar ranjib avatar renovate[bot] avatar scottmlikens avatar sethvargo avatar shoekstra avatar stevendanna avatar tas50 avatar timurb avatar xorima avatar xorimabot avatar znep avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

logrotate's Issues

Unclear position for settings

We've just had some fun time debugging some issues on AWS, so please excuse any sarcasm. ;)

What happened:

We have an AWS host configured via Chef and with a custom JSON file:

    "logrotate": {
        "ourproject": {
            "path": "/var/log/ourproject/*log",
            "missingok": true,
            "dateext": true,
            "dateyesterday": true,
            "rotate": 9999,
            "frequency": "daily",
            "sharedscripts": true
        }
    }

This almost worked, it only occurred us very late that the dateext was completely ignored! Da fuq? As it turned out, dateext (and probably some more parameters) must be specified like this:

    "logrotate": {
        "ourproject": {
            "path": "/var/log/ourproject/*log",
            "options": [
                "missingok",
                "dateext",
                "dateyesterday",
                "sharedscripts"
            ],
            "rotate": 9999,
            "frequency": "daily"
        }
    }

While this structure in and of itself isn't surprising, the ugly part is that e.g. sharedscripts can appear in multiple positions. However, when I have dateext under options, then sharedscripts must appear there, too, which presents another pitfall with confusing error messages.

My wishes:

  • Provide one and only one True Way to place parameters.
  • Allow any number of less true ways for backward compatibility. Those should generate warnings when used.
  • Fail with meaningful errors when some misguided soul uses the wrong parameter. Consider that some users don't actually understand Ruby!
  • Document the meaning of DIRECTIVES and VALUES (I believe those correspond to settings with and without values). Even without knowing Ruby, I might have figured out earlier what to do then.
  • The best to you for writing and sharing this code!

Update CONTRIBUTING.md

The CONTRIBUTING.md file currently in this cookbook is from when it was an Opscode cookbook. It no longer accurately reflects how to contribute to the cookbook. At a high level changes include:

  1. JIRA ticket NOT necessary. All work will be done on Github.
  2. CLA NOT necessary.
  3. Tests necessary

Version outdated on supermarket

The github repo has version 1.9.1, whereas the supermarket only has 1.8.1. Also the readme.md is messed up on supermarket.

Any plans to update it?

Using a list of lines for prerotate breaks formatting

The generated output is:

  prerotate
  # do stuff
# More info about stuff here.
stuff.sh --fou --barre
  endscript

It should be this:

  prerotate
    # do stuff
    # More info about stuff here.
    stuff.sh --fou --barre
  endscript

The differences are:

  • All lines of the script should be indented the same.
  • All lines of the script should be indented one level more than the surrounding prerotate and endscript tags.

Setting sharedscripts will be ignored

Hi, by setting sharedscripts to true on logrotate_app definition won't work. The setting is just missing in the logrotate file.

Best Regards,
Andreas

no implicit conversion of Chef::DelayedEvaluator into String

Hi,

When using chef-client > 12.6, the logrotate_app definition gives TypeError:

no implicit conversion of Chef::DelayedEvaluator into String

This is happening when I use the chef-client cookbook which uses the logrotate cookbook.

Recipe: logrotate::default
  * yum_package[logrotate] action install (up to date)
  * directory[/etc/logrotate.d] action create (up to date)
Recipe: chef-client::config
  * template[/etc/logrotate.d/chef-client] action create

    ================================================================================
    Error executing action `create` on resource 'template[/etc/logrotate.d/chef-client]'
    ================================================================================

    TypeError
    ---------
    no implicit conversion of Chef::DelayedEvaluator into String

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/logrotate/definitions/logrotate_app.rb

     63:     template "/etc/logrotate.d/#{params[:name]}" do
     64:       source   params[:template]
     65:       cookbook params[:cookbook]
     66:       mode     params[:template_mode]
     67:       owner    params[:template_owner]
     68:       group    params[:template_group]
     69:       backup   false
     70:       variables logrotate_config
     71:     end
     72:   else

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/logrotate/definitions/logrotate_app.rb:63:in `block in from_file'

    template("/etc/logrotate.d/chef-client") do
      params {:enable=>true, :frequency=>"weekly", :template=>"logrotate.erb", :cookbook=>"logrotate", :template_mode=>"0644", :template_owner=>"root", :template_group=>"root", :postrotate=>"systemctl reload chef-client.service >/dev/null || :", :prerotate=>nil, :firstaction=>nil, :lastaction=>nil, :sharedscripts=>false, :path=>["/var/log/chef/client.log"], :rotate=>12, :options=>["compress"], :name=>"chef-client"}
      action [:create]
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      source "logrotate.erb"
      cookbook "logrotate"
      variables {:path=>"\"/var/log/chef/client.log\"", :frequency=>"weekly", :options=>["compress"], :compresscmd=>nil, :uncompresscmd=>nil, :compressext=>nil, :compressoptions=>nil, :create=>nil, :dateformat=>nil, :include=>nil, :mail=>nil, :extension=>nil, :maxage=>nil, :minsize=>nil, :maxsize=>nil, :rotate=>12, :size=>nil, :shredcycles=>nil, :start=>nil, :tabooext=>nil, :su=>nil, :olddir=>nil, :firstaction=>"", :prerotate=>"", :postrotate=>"systemctl reload chef-client.service >/dev/null || :", :lastaction=>"", :preremove=>""}
      declared_type "template"
      cookbook_name "chef-client"
      recipe_name "config"
      mode "0644"
      owner "root"
      group "root"
      atomic_update #<Chef::DelayedEvaluator:0x000000036a71a8@/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.9.41/lib/chef/resource/file.rb:52>
      path #<Chef::DelayedEvaluator:0x000000036942d8@/opt/chef/embedded/lib/ruby/gems/2.1.0/gems/chef-12.9.41/lib/chef/property.rb:177>
    end

    Platform:
    ---------
    x86_64-linux


Running handlers:
Running handlers complete
Chef Client failed.

If I reinstall chef-client 12.6.x on the node, it completes the chef-client run successfully. If I then upgrade to a later chef-client version, the chef-client run fails again. Is this a known issue?

Thanks, Richard

logrorate_app skips only_if evaluation

logrorate_app skips only_if evaluation.
Ex-

node.set['logrotate']['enable'] = false

logrotate_app 'reactor' do
  path "/tmp/log/tomcat/reactor*log"
  size '64M'
  frequency 'weekly'
  rotate 9
  options %w(copytruncate compress notifempty missingok)

  only_if { node['logrotate']['enable'] }
end 

Output-

  - logrotate
Compiling Cookbooks...
Converging 3 resources
Recipe: logrotate::default
  * yum_package[logrotate] action install[2015-02-08T02:31:51-05:00] INFO: Processing yum_package[logrotate] action install (logrotate::default line 20)
 (up to date)
  * directory[/etc/logrotate.d] action create[2015-02-08T02:32:03-05:00] INFO: Processing directory[/etc/logrotate.d] action create (logrotate::default line 22)
 (up to date)
Recipe: test::default
  * template[/etc/logrotate.d/reactor] action create[2015-02-08T02:32:03-05:00] INFO: Processing template[/etc/logrotate.d/reactor] action create (test::default line 50)
[2015-02-08T02:32:03-05:00] INFO: template[/etc/logrotate.d/reactor] created file /etc/logrotate.d/reactor

    - create new file /etc/logrotate.d/reactor[2015-02-08T02:32:03-05:00] INFO: template[/etc/logrotate.d/reactor] updated file contents /etc/logrotate.d/reactor

    - update content in file /etc/logrotate.d/reactor from none to 8c8d02
    --- /etc/logrotate.d/reactor    2015-02-08 02:32:03.533364451 -0500
    +++ /tmp/chef-rendered-template20150208-17186-x77msp    2015-02-08 02:32:03.532364451 -0500
    @@ -1 +1,13 @@
    +# This file was generated by Chef for .
    +# Do not modify this file by hand!
    +
    +"/tmp/log/tomcat/reactor*log" {
    +  weekly
    +  size 64M
    +  rotate 9
    +  copytruncate
    +  compress
    +  notifempty
    +  missingok
    +}[2015-02-08T02:32:03-05:00] INFO: template[/etc/logrotate.d/reactor] owner changed to 0
[2015-02-08T02:32:03-05:00] INFO: template[/etc/logrotate.d/reactor] group changed to 0
[2015-02-08T02:32:03-05:00] INFO: template[/etc/logrotate.d/reactor] mode changed to 440

    - change mode from '' to '0440'
    - change owner from '' to 'root'
    - change group from '' to 'root'
    - restore selinux security context
[2015-02-08T02:32:03-05:00] WARN: Skipping final node save because override_runlist was given
[2015-02-08T02:32:03-05:00] INFO: Chef Run complete in 12.803214849 seconds
[2015-02-08T02:32:03-05:00] INFO: Skipping removal of unused files from the cache

Running handlers:
[2015-02-08T02:32:03-05:00] INFO: Running report handlers
Running handlers complete
[2015-02-08T02:32:03-05:00] INFO: Report handlers complete
Chef Client finished, 1/3 resources updated in 14.981741152 seconds

matcher does not verify path

I don't know how to fix it yet, so I can only offer a report at present.

    expect(chef_run).to enable_logrotate_app('foo').with(
      cookbook: 'logrotate',
      path: '/install/install-dir/logs/catalina.out',
      rotate: 5,
      su: 'rspec_user rspec_group'
  )

doesn't check that I've added the recipe with a correct path parameter.

Apparently unable to change global file?

Hi there. I have a recipe with code like so:

include_recipe 'logrotate'
include_recipe 'logrotate::global'

node.set['logrotate']['global']['compress'] = true

%w[ monthly weekly yearly ].each do |freq|
    node.set['logrotate']['global'][freq] = false
end

node.set['logrotate']['global']['daily'] = true
node.set['logrotate']['global']['rotate'] = 999

None of these seem to have an effect on the generated logrotate.conf file on the node. :/ Am I doing it wrong? Are there any examples I can see from a working recipe for changing Globals? Thanks in advance.

Release new version?

There's been quite a few commits since v1.4.0. Not to mention that the v1.4.0 tag actually points to the v1.3.0 release.

Since this cookbook is used by chef-client, and thus by all our service cookbooks, I'd like to see the feature in #43 and fix for #42 be released.

@stevendanna Any chance of a new version being released?

Support specify the time of day logrotate is executed?

Curious if you think this would be acceptable to support here. I think that would require you to use a mechanism other than /etc/cron.daily/, since that doesn't guarantee time of day run by design, so I understand if it would be stretching the scope of the cookbook.

Clarify that dateext is required for dateformat

The dateformat parameter for logrotate_app requires the dateext option be specified. This should be solved in one of two ways:

  1. Mention this in the README under the instruction for dateformat (perhaps even provide an example further down?)
  2. Automatically specify dateext when using dateformat in the template.

Error when running rspec

After I've done regular bundle install I've tried running tests but the following error appears:

$  bundle exec rspec
FFF

Failures:

  1) logrotate::default installs the logrotate package
     Failure/Error: expect(chef_run).to install_package('logrotate')
       No package resource matching name 'logrotate' with action :install found.
     # ./spec/unit/recipes/default_spec.rb:7:in `block (2 levels) in <top (required)>'

  2) logrotate::global includes the default recipe
     Failure/Error: expect(chef_run).to include_recipe('logrotate::default')
       expected: ['logrotate::default']
            got: []
     # ./spec/unit/recipes/global_spec.rb:7:in `block (2 levels) in <top (required)>'

  3) logrotate::global writes the configuration template
     Failure/Error: expect(template).to be
       expected nil to evaluate to true
     # ./spec/unit/recipes/global_spec.rb:12:in `block (2 levels) in <top (required)>'

Finished in 0.07624 seconds
3 examples, 3 failures

Failed examples:

rspec ./spec/unit/recipes/default_spec.rb:6 # logrotate::default installs the logrotate package
rspec ./spec/unit/recipes/global_spec.rb:6 # logrotate::global includes the default recipe
rspec ./spec/unit/recipes/global_spec.rb:10 # logrotate::global writes the configuration template

I'm running Ubuntu 13.10 x64 with ruby 1:1.9.3 installed (ruby 1.9.3p194) and bundler 1.5.3 installed.

Foodcritic and rubocop pass ok.

Should ensure that /etc/cron.hourly/logrotate exists

This cookbook allows the specification of hourly as an option, but it does not guarantee that an hourly cron entry exists.

$ ls -l /etc/cron.{hourly,daily}/logrotate
ls: cannot access /etc/cron.hourly/logrotate: No such file or directory
-rwxr-xr-x 1 root root 372 Jan 22  2014 /etc/cron.daily/logrotate

This issue is commonly asked about. The logrotate man page provides this guidance.

Log files are rotated every hour. Note that usually logrotate is configured to be run by cron daily. You have to change this configuration and run logrotate hourly to be able to really rotate logs hourly.

In my opinion, this cookbook should create /etc/cron.hourly/logrotate if the hourly option is used for any definitions of logrotate_app.

Anything chef-brigade can do to help?

Is there anything @chef-brigade can do to help out? We're probably going to start using this in our infra, so we want to keep it awesome.

If you need any administrative help, want a slack channel, website, testing infra &c, just let us know. It doesn't need to have the brigade name anywhere on it.

had an error: NoMethodError: undefined method `declared_type=' for Chef::Resource::Directory

I m using version 2.1.0, Things were good with version 1.9.2, since new release we are facing the issue,

Cookbook Trace:
---------------
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/resource_builder.rb:58:in build' /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb:109:inbuild_resource'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/dsl/declare_resource.rb:67:in declare_resource' /var/chef/cache/cookbooks/logrotate/resources/app.rb:60:inblock in class_from_file'
/var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:118:in instance_eval' /var/chef/cache/cookbooks/compat_resource/files/lib/chef_compat/copied_from_chef/chef/provider.rb:118:incompile_and_converge_action'

NoMethodError
-------------
undefined method `declared_type=' for Chef::Resource::Directory

logrotate_app 'nginx' do
cookbook 'logrotate'
path '/var/log/nginx/*.log'
frequency 'weekly'
rotate 4
create '644 root root'
end

package 'source' and 'version' attributes using provider

the package resource for node["logrotate"]["package"]["name"] has guards that look for source and version and in both cases end up using provider instead of source and version respectively.

package node["logrotate"]["package"]["name"] do
  provider node["logrotate"]["package"]["provider"] if node["logrotate"]["package"]["provider"]
  source node["logrotate"]["package"]["provider"] if node["logrotate"]["package"]["source"]
  version node["logrotate"]["package"]["provider"] if node["logrotate"]["package"]["version"]
  action :upgrade
end

Parameter 'create' does not appear to work

This code below,

logrotate_app 'opscode-nginx' do
  path '/var/log/opscode-analytics/nginx/*.log'
  options %w(notifempty compress delaycompress copytruncate)
  frequency 'daily'
  rotate 21
  create '644 root root'
end

Does not appear to honor the create parameter:

 --- /etc/logrotate.d/opscode-nginx  2016-06-09 07:20:11.878360564 -0700
    +++ /tmp/chef-rendered-template20160609-21371-hsp3g3        2016-06-09 07:20:11.878360564 -0700
    @@ -1 +1,13 @@
    +# This file was generated by Chef for <redacted-server-name>.
    +# Do not modify this file by hand!
    +
    +"/var/log/opscode-analytics/nginx/*.log" {
    +  daily
    +  create 644 root root
    +  rotate 21
    +  notifempty
    +  compress
    +  delaycompress
    +  copytruncate
    +}
    - change mode from '' to '0440'
    - change owner from '' to 'root'
    - change group from '' to 'root'

Here is the file with 440 instead of 644:

[root@redacted logrotate.d]# ll ops*
-r--r----- 1 root root 247 Jun  9 07:20 opscode-nginx

I'm using v1.9.2 of this cookbook on RHEL6. Logrotate (yum package) info:

Arch        : x86_64
Version     : 3.7.8
Release     : 26.el6_7

merge into chef core

I find myself using the logrotate_app resource in half of my cookbooks in order to maintain logs. Is there any plans on merging it into the core functionality of chef?

Changelog

Hey Steven,

Any chance you can update the changelog to match the current release on the supermarket?

Thanks,
Tim

undefined method `each' for nil:NilClass

==> default: * template[/etc/logrotate.d/tomcat-myapp] action create
==> default:
==> default: ================================================================================
==> default: Error executing action create on resource 'template[/etc/logrotate.d/tomcat-myapp]'
==> default: ================================================================================
==> default:
==> default: Chef::Mixin::Template::TemplateError
==> default: ------------------------------------
==> default: undefined method each' for nil:NilClass ==> default: ==> default: Resource Declaration: ==> default: --------------------- ==> default: # In /var/chef/cache/cookbooks/logrotate/definitions/logrotate_app.rb ==> default: ==> default: 28: template "/etc/logrotate.d/#{params[:name]}" do ==> default: 29: source params[:template] ==> default: 30: cookbook params[:cookbook] ==> default: 31: mode 0440 ==> default: 32: owner "root" ==> default: 33: group "root" ==> default: 34: backup false ==> default: 35: variables( ==> default: 36: :path => path, ==> default: 37: :create => create, ==> default: 38: :frequency => params[:frequency], ==> default: 39: :rotate => params[:rotate] ==> default: 40: ) ==> default: 41: end ==> default: 42: ==> default: ==> default: Compiled Resource: ==> default: ------------------ ==> default: # Declared in /var/chef/cache/cookbooks/logrotate/definitions/logrotate_app.rb:28:in block in from_file'
==> default:
==> default: template("/etc/logrotate.d/tomcat-myapp") do
==> default: params {:enable=>true, :frequency=>"daily", :template=>"logrotate.erb", :cookbook=>"logrotate", :path=>"/var/log/tomcat/myapp.log", :options=>["missingok", "delaycompress", "notifempty"], :rotate=>30, :create=>"644 root adm", :name=>"tomcat-myapp"}
==> default: action [:create]
==> default: default_guard_interpreter :default
==> default: source "logrotate.erb"
==> default: declared_type :template
==> default: cookbook_name "combine_server"
==> default: recipe_name "log_rotate"
==> default: cookbook "logrotate"
==> default: mode 288
==> default: owner "root"
==> default: group "root"
==> default: variables {:path=>["/var/log/tomcat/myapp.log"], :create=>"644 root adm", :frequency=>"daily", :rotate=>30}
==> default: path "/etc/logrotate.d/tomcat-myapp"
==> default: verifications []
==> default: end
==> default:
==> default: Template Context:
==> default: -----------------
==> default: on line #8
==> default: 6: <%= @frequency %>
==> default: 7: <%- end %>
==> default: 8: <%- @configurables.each do |name, value| %>
==> default: 9: <%= "#{name} #{value}" %>
==> default: 10: <%- end %>
==> default:
==> default: System Info:
==> default: ------------
==> default: chef_version=14.8.12
==> default: platform=centos
==> default: platform_version=7.6.1810
==> default: ruby=ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux]
==> default: program_name=/usr/bin/chef-solo
==> default: executable=/opt/chef/bin/chef-solo

skipping "/var/log/syslog" because parent directory has insecure permissions

error: skipping "/var/log/syslog" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

Some/recent logrotate versions (3.8.7+, ubuntu 16.04) fail to rotate logs without an "su" directive added to the logrotate config telling it which user/group to run as.

Old versions of logrotate (ubuntu 12.04?) fail when they see an unknown/unexpected "su" directive in the config file.

The naive solution is to run logrotate --version and for recent versions add a su username groupname where username and groupname reflect the owner of the directory containing the file being rotated.

My ruby/chef foo isn't really up to it, deliriously hoping someone else has already run into this and has a lovely fix they haven't thought to send upstream.

Support maxage option

The definition does not support the maxage option, either as a variable or within the options array. I can submit a pull request, but wanted to check if that was intentional for some reason?

How to include maxage parameter in logrotate file ?

Hi,
I have the logrotate cookbook which I have used in my deploy recipe to include the logrotation of log files.
Below is the blog from my file for creating the logrotate file for app logs.
logrotate_app 'app' do path ["#{node['deploy']['logdir']}/#{node['deploy']['nodejs']['application_name']}/app*log"] size '5M' frequency 'daily' rotate 5 options ['missingok', 'delaycompress', 'notifempty', 'sharedscripts', 'copytruncate'] create "664 #{node['deploy']['user']} root" end

Can you please help me in including the maxage parameter with correct syntax as I am unable to do so?
I tried adding as : -
maxage 60
maxage=>60
But the file is not getting updated after running the chef-client on the server due to some syntax mismatch.

Thanks

Failure messages reflect wrong actual parameter

Currently unmatched_parameters method where expected and actual parameters are computed, the logic to compute actual parameter should be changed because safe_send(parameter) only works for cookbook everything else needs to come from variable.
Basically it needs to share the logic used in matches_parameter?
I will submit the PR soon

Foodcritic error FC109

FC109: Use platform-specific package resources instead of provider property: ./recipes/default.rb:23. Code from the recipe is:

package node['logrotate']['package']['name'] do
provider node['logrotate']['package']['provider'] if node['logrotate']['package']['provider']
source node['logrotate']['package']['source'] if node['logrotate']['package']['source']
version node['logrotate']['package']['version'] if node['logrotate']['package']['version']
action node['logrotate']['package']['action']
end

Global frequency

Hi,
I'm trying to change the global frequency to "daily" with no luck.

I tried, following the readme, to do:

%w[ weekly monthly yearly ].each do |freq|
  node.override['logrotate']['global'][freq] = false
end
node.override['logrotate']['global']['daily'] = true

But /etc/logrotate.conf seems un-touched

I also tried to specify some logrotate_app and they work perfectly, thank you for your work!

Target is CentOs7 (if it helps)

new release

It would be nice to get 1fcb3ff released, as logrotate::global isn't usable for me without it on Ubuntu 14.04.

By the way, the cookbook has been great, thanks for sharing it!

logrotate constant initialized warning

I've been running into a bunch of warnings when testing cookbooks that depend on logrotate. I keep getting:

logrotate_config.rb:2: warning: already initialized constant CookbookLogrotate::DIRECTIVES
logrotate_config.rb:2: warning: previous definition of DIRECTIVES was here
logrotate_config.rb:11: warning: already initialized constant CookbookLogrotate::VALUES
logrotate/libraries/logrotate_config.rb:11: warning: previous definition of VALUES was here
logrotate/libraries/logrotate_config.rb:18: warning: previous definition of SCRIPTS was here
logrotate/libraries/logrotate_config.rb:20: warning: already initialized constant CookbookLogrotate::DIRECTIVES_AND_VALUES
logrotate/libraries/logrotate_config.rb:20: warning: previous definition of DIRECTIVES_AND_VALUES was here

Issue with Variable Evaluation

For one reason or another, logrotate_app seems to have a problem evaluating Resource Properties.

If I try passing in service_user as create "644 #{service_user} #{service_user}"

  Recipe: <Dynamically Defined Resource>
    * template[/etc/logrotate.d/MyApp] action create
      - update content in file /etc/logrotate.d/MyApp from f37b2e to 2ac241
      --- /etc/logrotate.d/MyApp       2016-01-22 17:44:23.244140684 -0700
      +++ /etc/logrotate.d/.MyApp20160122-28294-36d27x 2016-01-22 17:46:41.888167833 -0700
      @@ -3,7 +3,7 @@

       "/var/log/MyApp/error.log" {
         daily
      -  create 644 root root
      +  create 644 [] []
         rotate 30
         missingok
         delaycompress
    * template[PHP Configuration (MyApp)] action create (up to date)

This doesn't work

Defined as property :service_name, String, name_property: true
  logrotate_app service_name do
    cookbook  'logrotate'
    path [::File.join(log_dir, 'error.log')]
    frequency 'daily'
    options ['missingok', 'delaycompress', 'notifempty']
    postrotate "invoke-rc.d #{service_name}  reopen-logs > /dev/null"
    sharedscripts true
    rotate 30
    create '644 root root'
  end

This Works

  lr_service_name = service_name
  logrotate_app service_name do
    cookbook  'logrotate'
    path [::File.join(log_dir, 'error.log')]
    frequency 'daily'
    options ['missingok', 'delaycompress', 'notifempty']
    postrotate "invoke-rc.d #{lr_service_name}  reopen-logs > /dev/null"
    sharedscripts true
    rotate 30
    create '644 root root'
  end

Finally, if you try to use a lazy evaluator, it passes the lazy evaluator object as a string.

Logrotate failed if logrotate status file got corrupted

[Problem]
Logrotate failed if logrotate status file got corrupted.
[root]# /usr/sbin/logrotate /etc/logrotate.conf
error: line 92 too long in state file /var/lib/logrotate.status
error: could not read state file, will not attempt to write into it
[Reason]
logroatet.c check each line of logrotate status file which is terminated with new line,
if it fails it return and exist with error.
while (fgets(buf, sizeof(buf) - 1, f)) {
argv = NULL;
line++;
i = strlen(buf);
if (buf[i - 1] != '\n') {
message(MESS_ERROR, "line %d too long in state file %s\n",
line, stateFilename);
fclose(f);
return 1;
}

/var/lib/logrotate.status contains line number 92 ,
which exist without newline and thus causing this issue.
89 "/var/log/vsftpd.log" 2016-3-18
90 "/var/log/actlog.exports/meminfo" 2016-10-8
91 "/var/log/boot.log" 2016-10-2
92 "/var/log/network/update_swi
[Workaround]
Remove bad line and restart log rotate.

the metadata.rb file will break the OpsWorks command

When we try to run a OpsWorks command in our stack, it failed with the log below.

as chef/chef#2937 mentioned, such change will break the ones who are using Chef < 12, while we are currently using Chef 11.10.

Is that possible to make it compatible to old versions?

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received '47'
---- Begin output of /opt/aws/opsworks/local/bin/berks vendor /opt/aws/opsworks/current/berkshelf-cookbooks ----
STDOUT: Resolving cookbook dependencies...
Fetching 'build-essential' from git://github.com/opscode-cookbooks/build-essential.git (at v1.4.2)
Fetching 'conffile' from git://github.com/optiflows-cookbooks/conffile.git (at master)
Fetching 'logrotate' from git://github.com/stevendanna/logrotate.git (at master)
STDERR: Ridley::Errors::FromFileParserError Could not parse /tmp/d20160428-32603-xmzigf/metadata.rb': undefined methodsource_url' for #Ridley::Chef::Cookbook::Metadata:0x007fd69a5b3ce0
---- End output of /opt/aws/opsworks/local/bin/berks vendor /opt/aws/opsworks/current/berkshelf-cookbooks ----
Ran /opt/aws/opsworks/local/bin/berks vendor /opt/aws/opsworks/current/berkshelf-cookbooks returned 47

Parameter 'cookbook' doesn't work

Hello guys,

I'm using your cookbook for a long time, and now I noticed one issue:

"NoMethodError

undefined method `cookbook' for Custom resource logrotate_app from cookbook logrotate

Cookbook Trace:

/tmp/chef-solo/cookbooks/logrotate-scup/recipes/default.rb:30:in block in from_file' /tmp/chef-solo/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_builder.rb:90:ininstance_eval'
/tmp/chef-solo/cookbooks/compat_resource/files/lib/chef_compat/monkeypatches/chef/resource_builder.rb:90:in build' /tmp/chef-solo/cookbooks/logrotate-scup/recipes/default.rb:29:infrom_file'

Relevant File Content:

/tmp/chef-solo/cookbooks/logrotate-scup/recipes/default.rb:

23:
24: if node[:logrotate_scup][:sudo_enabled]
25: include_recipe "logrotate-scup::sudo_options"
26: else
27:
28: if node[:logrotate_scup][:app][:name] == "plataforma"
29: logrotate_app node['logrotate_scup']['app']['name'] do
30>> cookbook 'logrotate'
31: path node['logrotate_scup']['app']['path']
32: frequency node['logrotate_scup']['app']['frequency']
33: rotate node['logrotate_scup']['app']['rotate']
34: create node['logrotate_scup']['app']['create']
35: end
36: end
37:
38: if node[:logrotate_scup][:app][:name] != "plataforma"
39: logrotate_app node['logrotate_scup']['app']['name'] do
"

I created one cookbook that I'm using by interface, my parameters are:

logrotate_app node['logrotate_scup']['app']['name'] do
cookbook 'logrotate'
path node['logrotate_scup']['app']['path']
frequency node['logrotate_scup']['app']['frequency']
rotate node['logrotate_scup']['app']['rotate']
create node['logrotate_scup']['app']['create']
size node['logrotate_scup']['app']['size']
end

The tag v1.7.0 still works well, but code of master branch has this issue.

Recipe Compile Error in logrotate recipe using chef solo and vagrant in matchers.rb

==> default: Recipe Compile Error in /tmp/vagrant-chef-4/chef-solo-1/cookbooks/logrotate/libraries/matchers.rb
==> default: ================================================================================
==> default:
==> default: SyntaxError
==> default: -----------
==> default: /tmp/vagrant-chef-4/chef-solo-1/cookbooks/logrotate/libraries/matchers.rb:104: odd number list for Hash
==> default: expected: expected,
==> default: ^
==> default: /tmp/vagrant-chef-4/chef-solo-1/cookbooks/logrotate/libraries/matchers.rb:104: syntax error, unexpected ':', expecting '}'
==> default:
==> default: expected: expected,
==> default: ^
==> default:
==> default: /tmp/vagrant-chef-4/chef-solo-1/cookbooks/logrotate/libraries/matchers.rb:105: syntax error, unexpected ':', expecting '='
==> default: actual: safe_send(parameter),
==> default: ^
==> default:

Changelog does not document removal of `create:` option for resource

While converging a node whose run list includes a recipe which runs the logrotate_app resource with the create: option, in version 1.9.2, it sets the correct mode/user/group. When a colleague tried converging, it downloaded v2.1.0. The logrotate file created had the incorrect mode/user/group (644/root/root instead of what was specified in create:).

I checked the cookbook and it seems that property has been removed from the resource definition. This is a breaking change that is not documented in the changelog or README. It would be helpful if it were.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.