├── .editorconfig ├── .envrc ├── .gitattributes ├── .github ├── CODEOWNERS └── workflows │ ├── ci.yml │ └── stale.yml ├── .gitignore ├── .markdownlint-cli2.yaml ├── .mdlrc ├── .overcommit.yml ├── .rubocop.yml ├── .vscode └── extensions.json ├── .yamllint ├── Berksfile ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── Dangerfile ├── LICENSE ├── README.md ├── TESTING.md ├── chefignore ├── documentation ├── .gitkeep ├── logrotate_app.md ├── logrotate_global.md └── logrotate_package.md ├── kitchen.dokken.yml ├── kitchen.exec.yml ├── kitchen.global.yml ├── kitchen.yml ├── libraries ├── logrotate.rb └── template.rb ├── metadata.rb ├── renovate.json ├── resources ├── app.rb ├── global.rb └── package.rb ├── spec ├── spec_helper.rb └── unit │ └── resources │ ├── app_spec.rb │ ├── global_spec.rb │ └── package_spec.rb ├── templates ├── logrotate-global.erb └── logrotate.erb └── test ├── cookbooks └── test │ ├── metadata.rb │ ├── recipes │ ├── app.rb │ ├── default.rb │ └── global.rb │ └── templates │ └── logrotate.erb └── integration └── default ├── global_spec.rb └── resources_spec.rb /.editorconfig: -------------------------------------------------------------------------------- 1 | # https://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root=true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 2 space indentation 12 | indent_style = space 13 | indent_size = 2 14 | 15 | # Avoid issues parsing cookbook files later 16 | charset = utf-8 17 | 18 | # Avoid cookstyle warnings 19 | trim_trailing_whitespace = true 20 | -------------------------------------------------------------------------------- /.envrc: -------------------------------------------------------------------------------- 1 | use chefworkstation 2 | export KITCHEN_GLOBAL_YAML=kitchen.global.yml 3 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @sous-chefs/maintainers 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: ci 3 | 4 | "on": 5 | pull_request: 6 | push: 7 | branches: 8 | - main 9 | 10 | jobs: 11 | lint-unit: 12 | uses: sous-chefs/.github/.github/workflows/lint-unit.yml@3.1.1 13 | permissions: 14 | actions: write 15 | checks: write 16 | pull-requests: write 17 | statuses: write 18 | issues: write 19 | 20 | integration: 21 | needs: "lint-unit" 22 | runs-on: ubuntu-latest 23 | strategy: 24 | matrix: 25 | os: 26 | - "almalinux-9" 27 | - "amazonlinux-2023" 28 | - "centos-stream-9" 29 | - "centos-stream-10" 30 | - "debian-11" 31 | - "debian-12" 32 | # - "opensuse-leap-15" 33 | - "ubuntu-2204" 34 | - "ubuntu-2404" 35 | suite: 36 | - "default" 37 | fail-fast: false 38 | 39 | steps: 40 | - name: Check out code 41 | uses: actions/checkout@v4 42 | - name: Install Chef 43 | uses: actionshub/chef-install@3.0.1 44 | - name: Dokken 45 | uses: actionshub/test-kitchen@3.0.0 46 | env: 47 | CHEF_LICENSE: accept-no-persist 48 | KITCHEN_LOCAL_YAML: kitchen.dokken.yml 49 | CHEF_VERSION: ${{ vars.CHEF_VERSION }} 50 | with: 51 | suite: ${{ matrix.suite }} 52 | os: ${{ matrix.os }} 53 | - name: Print debug output on failure 54 | if: failure() 55 | run: | 56 | set -x 57 | sudo journalctl -l --since today 58 | KITCHEN_LOCAL_YAML=kitchen.dokken.yml /usr/bin/kitchen exec ${{ matrix.suite }}-${{ matrix.os }} -c "journalctl -l" 59 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Mark stale issues and pull requests 3 | 4 | "on": 5 | schedule: [cron: "0 0 * * *"] 6 | 7 | jobs: 8 | stale: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/stale@v9 12 | with: 13 | repo-token: ${{ secrets.GITHUB_TOKEN }} 14 | close-issue-message: > 15 | Closing due to inactivity. 16 | If this is still an issue please reopen or open another issue. 17 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 18 | Thanks, Sous-Chefs. 19 | days-before-close: 7 20 | days-before-stale: 365 21 | stale-issue-message: > 22 | Marking stale due to inactivity. 23 | Remove stale label or comment or this will be closed in 7 days. 24 | Alternatively drop by the #sous-chefs channel on the [Chef Community Slack](http://community-slack.chef.io/) and we'll be happy to help! 25 | Thanks, Sous-Chefs. 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.rbc 2 | .config 3 | InstalledFiles 4 | pkg 5 | test/tmp 6 | test/version_tmp 7 | tmp 8 | _Store 9 | *~ 10 | *# 11 | .#* 12 | \#*# 13 | *.un~ 14 | *.tmp 15 | *.bk 16 | *.bkup 17 | 18 | # editor files 19 | .idea 20 | .*.sw[a-z] 21 | 22 | # ruby/bundler/rspec files 23 | .ruby-version 24 | .ruby-gemset 25 | .rvmrc 26 | Gemfile.lock 27 | .bundle 28 | *.gem 29 | coverage 30 | spec/reports 31 | 32 | # YARD / rdoc artifacts 33 | .yardoc 34 | _yardoc 35 | doc/ 36 | rdoc 37 | 38 | # chef infra stuff 39 | Berksfile.lock 40 | .kitchen 41 | kitchen.local.yml 42 | vendor/ 43 | .coverage/ 44 | .zero-knife.rb 45 | Policyfile.lock.json 46 | 47 | # vagrant stuff 48 | .vagrant/ 49 | .vagrant.d/ 50 | -------------------------------------------------------------------------------- /.markdownlint-cli2.yaml: -------------------------------------------------------------------------------- 1 | config: 2 | ul-indent: false # MD007 3 | line-length: false # MD013 4 | no-duplicate-heading: false # MD024 5 | reference-links-images: false # MD052 6 | ignores: 7 | - .github/copilot-instructions.md 8 | -------------------------------------------------------------------------------- /.mdlrc: -------------------------------------------------------------------------------- 1 | rules "~MD013", "~MD024", "~MD025" 2 | -------------------------------------------------------------------------------- /.overcommit.yml: -------------------------------------------------------------------------------- 1 | --- 2 | PreCommit: 3 | TrailingWhitespace: 4 | enabled: true 5 | YamlLint: 6 | enabled: true 7 | required_executable: "yamllint" 8 | ChefSpec: 9 | enabled: true 10 | required_executable: "chef" 11 | command: ["chef", "exec", "rspec"] 12 | Cookstyle: 13 | enabled: true 14 | required_executable: "cookstyle" 15 | command: ["cookstyle"] 16 | MarkdownLint: 17 | enabled: false 18 | required_executable: "npx" 19 | command: ["npx", "markdownlint-cli2", "'**/*.md'"] 20 | include: ["**/*.md"] 21 | 22 | CommitMsg: 23 | HardTabs: 24 | enabled: true 25 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | require: 2 | - cookstyle 3 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "chef-software.chef", 4 | "rebornix.ruby", 5 | "editorconfig.editorconfig", 6 | "DavidAnson.vscode-markdownlint" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | rules: 4 | line-length: 5 | max: 256 6 | level: warning 7 | document-start: disable 8 | braces: 9 | forbid: false 10 | min-spaces-inside: 0 11 | max-spaces-inside: 1 12 | min-spaces-inside-empty: -1 13 | max-spaces-inside-empty: -1 14 | comments: 15 | min-spaces-from-content: 1 16 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | group :integration do 6 | cookbook 'test', path: 'test/cookbooks/test' 7 | end 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # logrotate Cookbook CHANGELOG 2 | 3 | This file is used to list changes made in each version of the logrotate cookbook 4 | 5 | ## Unreleased 6 | 7 | ## 3.0.29 - *2025-02-12* 8 | 9 | ## 3.0.28 - *2025-01-06* 10 | 11 | ## 3.0.27 - *2024-11-18* 12 | 13 | Standardise files with files in sous-chefs/repo-management 14 | 15 | ## 3.0.26 - *2024-07-15* 16 | 17 | Standardise files with files in sous-chefs/repo-management 18 | 19 | ## 3.0.25 - *2024-05-06* 20 | 21 | No notable changes 22 | 23 | ## 3.0.24 - *2024-05-06* 24 | 25 | No notable changes 26 | 27 | ## 3.0.23 - *2023-09-28* 28 | 29 | No notable changes 30 | 31 | ## 3.0.22 - *2023-09-04* 32 | 33 | No notable changes 34 | 35 | ## 3.0.21 - *2023-07-10* 36 | 37 | No notable changes 38 | 39 | ## 3.0.20 - *2023-05-17* 40 | 41 | No notable changes 42 | 43 | ## 3.0.19 - *2023-04-07* 44 | 45 | Standardise files with files in sous-chefs/repo-management 46 | 47 | ## 3.0.18 - *2023-04-01* 48 | 49 | No notable changes 50 | 51 | ## 3.0.17 - *2023-04-01* 52 | 53 | No notable changes 54 | 55 | ## 3.0.16 - *2023-04-01* 56 | 57 | Standardise files with files in sous-chefs/repo-management 58 | 59 | ## 3.0.15 - *2023-03-02* 60 | 61 | No notable changes 62 | 63 | ## 3.0.14 - *2023-02-27* 64 | 65 | Standardise files with files in sous-chefs/repo-management 66 | 67 | ## 3.0.13 - *2023-02-16* 68 | 69 | Standardise files with files in sous-chefs/repo-management 70 | 71 | ## 3.0.12 - *2023-02-14* 72 | 73 | ## 3.0.11 - *2023-02-14* 74 | 75 | Standardise files with files in sous-chefs/repo-management 76 | 77 | ## 3.0.10 - *2022-12-06* 78 | 79 | Standardise files with files in sous-chefs/repo-management 80 | 81 | ## 3.0.9 - *2022-02-17* 82 | 83 | Standardise files with files in sous-chefs/repo-management 84 | 85 | ## 3.0.8 - *2022-02-08* 86 | 87 | Remove delivery folder 88 | 89 | ## 3.0.7 - *2022-02-01* 90 | 91 | Update tested platforms 92 | 93 | ## 3.0.6 - *2022-01-14* 94 | 95 | Do not sort options as the order can be important 96 | 97 | ## 3.0.5 - *2021-11-03* 98 | 99 | Add CentOS Stream 8 to CI pipeline 100 | 101 | ## 3.0.4 - *2021-08-30* 102 | 103 | Standardise files with files in sous-chefs/repo-management 104 | 105 | ## 3.0.3 - *2021-06-01* 106 | 107 | Standardise files with files in sous-chefs/repo-management 108 | 109 | ## 3.0.2 - *2021-05-12* 110 | 111 | Fix passing options to global path declarations 112 | 113 | ## 3.0.1 - *2021-05-12* 114 | 115 | - Update chef_version to >= 15.3 to require unifed_mode works 116 | 117 | ## 3.0.0 - *2021-05-10* 118 | 119 | - Replace recipes and attributes with Chef 17 compliant resources 120 | - Remove attributes 121 | - Remove recipes 122 | - Replace default recipe with package and global resource 123 | - Enable unified_mode on all resources. 124 | 125 | ## 2.3.0 - *2021-02-10* 126 | 127 | - Sous Chefs Adoption 128 | - Fix cookstyle issues 129 | - mdl and yamlint fixes 130 | - Audit kitchen platforms 131 | 132 | ## 2.2.3 (2020-06-02) 133 | 134 | - Remove opensuse platform from metadata.rb as it's no longer valid - [@tas50](https://github.com/tas50) 135 | - Don't fail on deprecated properties - [@tas50](https://github.com/tas50) 136 | - Require Chef 12.15+ - [@tas50](https://github.com/tas50) 137 | - Standardise files with files in chef-cookbooks/repo-management - [@xorimabot](https://github.com/xorimabot) 138 | - Resolved deprecations to provide Chef Infra Client 16 compatibility - [@xorimabot](https://github.com/xorimabot) 139 | - Resolved cookstyle error: resources/app.rb:17:1 warning: `ChefDeprecations/ResourceUsesOnlyResourceName` 140 | 141 | ## 2.2.2 (2019-10-01) 142 | 143 | - Update build badge with chef-cookbooks namespace - [@jasonwbarnett](https://github.com/jasonwbarnett) 144 | - Use our standard delivery config and stop testing with Foodcritic - [@tas50](https://github.com/tas50) 145 | - Switch the maintainer over to Chef Software - [@tas50](https://github.com/tas50) 146 | - Remove deprecated metadata fields - [@tas50](https://github.com/tas50) 147 | - Remove ChefSpec matchers that are autogenerated now - [@tas50](https://github.com/tas50) 148 | - Use Ubuntu 18.04 in the specs not 16.04 - [@tas50](https://github.com/tas50) 149 | - Update the kitchen configs with the latest platforms - [@tas50](https://github.com/tas50) 150 | - Add updated testing.md and contributing.md files - [@tas50](https://github.com/tas50) 151 | 152 | ## 2.2.1 (2019-10-01) 153 | 154 | - Avoid deprecation warnings in the chefspecs - [@tas50](https://github.com/tas50) 155 | - Resolve foodcritic license warning - [@tas50](https://github.com/tas50) 156 | - There's no need to define a default action in a custom resource - [@tas50](https://github.com/tas50) 157 | - Move templates out of default dir and remove node name - [@tas50](https://github.com/tas50) 158 | - Remove the mention of Ruby 2.0 in the contributing docs - [@tas50](https://github.com/tas50) 159 | - Add initial kitchen-dokken config - [@tas50](https://github.com/tas50) 160 | - Use our standard chefignore file - [@tas50](https://github.com/tas50) 161 | - Rename fake recipe to test and definitions -> resources - [@tas50](https://github.com/tas50) 162 | - Convert to inspec from serverspec - [@tas50](https://github.com/tas50) 163 | - Remove the default test kitchen suite since global includes it - [@tas50](https://github.com/tas50) 164 | - Remove references to the definition from the metadata - [@tas50](https://github.com/tas50) 165 | - Expand platforms we test on in Test Kitchen - [@tas50](https://github.com/tas50) 166 | - Remove unused prep recipe - [@tas50](https://github.com/tas50) 167 | - Add suse platforms to the metadata now that we test them - [@tas50](https://github.com/tas50) 168 | - Format readme and remove references to the definition - [@tas50](https://github.com/tas50) 169 | - Fix alignment for multiple scripts - [@shoekstra](https://github.com/shoekstra) 170 | - Ignore FC109 - [@shoekstra](https://github.com/shoekstra) 171 | - Update /var/log/btmp default permissions - [@jasonwbarnett](https://github.com/jasonwbarnett) 172 | 173 | ## 2.2.0 174 | 175 | - The `compat_resource` dependency was removed. This means we now require Chef 12.5 or higher. It also means we now better support Chef 13. 176 | - The global configuration now supports scripts. 177 | - The package install action (upgrade by default) is now configurable via an attribute. 178 | - The development environment now more closely follows modern cookbook practices. 179 | - ChefSpec matcher now correctly calls ChefSpec.define_matcher. 180 | 181 | ## 2.1.0 182 | 183 | - Restore `cookbook` parameter for `logrotate_app` resource due to popular demand. 184 | - Add a `template_name` parameter to replace the 1.x `template` parameter. The name `template` can't be used inside a resource without conflicting with an attribute of the same name. 185 | - Fix exception when `options` specified as a string rather than an array 186 | 187 | ## 2.0.0 188 | 189 | - Convert the logrotate_app definition to a resource 190 | - Accept all options included in logrotate 3.9.2 191 | - The `cookbook` parameter to `logrotate_app` is no longer accepted. 192 | 193 | ## 1.9.2 194 | 195 | - Fix deprecation warnings from ChefSpec 196 | 197 | ## 1.9.1 198 | 199 | - Fixes regression in the sharedscripts logrotate_app parameter (Bug #69) 200 | 201 | ## 1.9.0 202 | 203 | - All configuration options from the logrotate 3.8.8 manual page can be used by the global configuration and the logrotate_app definition. 204 | - Berkshelf is no longer a development dependency of the logrotate cookbook. 205 | - Rubocop lint failures have been resolved. 206 | 207 | ## 1.8.0 208 | 209 | - `su` parameter now supported in global config. 210 | - firstaction and lastaction attributes documented in the README 211 | - rotate attribute documented in the README 212 | - Use hash-rocket syntax in rspec matcher to maintain 1.9 support. 213 | 214 | ## 1.7.0 215 | 216 | - Use `raise` rather than Application.fatal! to prevent killing a daemonized chef-client 217 | - Chefspec matcher for logrotate_app definition 218 | - Support the following options: compressoptions, maxage, shred/shredcycles, extension, tabooext 219 | - Add Solaris support 220 | 221 | ## 1.6.0 222 | 223 | - Fix documentation error 224 | - Support for options "compresscmd", "uncompresscmd", "compressext" 225 | - Allow nodateext as parameter for logrotate_app definition 226 | - Move to chefspec ~> 3.0 227 | 228 | ## 1.5.0 229 | 230 | - Fix missing end tag in template 231 | - Don't re-initialize constants. 232 | - Fix rubocop finding 233 | - Allow to use maxsize parameter. 234 | - Allow to use dateyesterday option. 235 | - Allow to use su parameter. 236 | - Allows use of the dateformat parameter. 237 | - Loosen test-kitchen version constraint 238 | - Add rvm files to gitignore 239 | 240 | ## 1.4.0 241 | 242 | - Raise Exception when adding more than one invalid option 243 | - Do not duplicate template entires for multiple paths 244 | - Update logrotate_app params to accept arrays and strings 245 | - Add ability to choose file mode for logrotate template 246 | 247 | ## 1.3.0 248 | 249 | - Add optional `frequency` and `rotate` params when defined globally 250 | - Use `Array` instead of `respond_to?(:each)` 251 | - Change `logrotate.d` config file mode to `0644` 252 | - Add `minsize` 253 | - Fix README typo that suggested the opposite action 254 | - Add `olddir` option 255 | - Add `dateext` ability 256 | 257 | ## 1.2.2 258 | 259 | - Add firstaction/lastaction ability to logrotate 260 | - Argument error in `logrotate_app` definition 261 | 262 | ## 1.2.0 263 | 264 | - Add the ability to manage the global logrotate configuration 265 | 266 | ## 1.1.0 267 | 268 | - Logrotate size parameter 269 | 270 | ## 1.0.2 271 | 272 | - Add support for pre-/post-rotate commands 273 | - Update log rotate for more flexibility of rotate options 274 | - "Create" isn't a mandatory option 275 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Guidelines 2 | 3 | This project follows the Chef Community Guidelines 4 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please refer to 4 | [https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/CONTRIBUTING.MD) 5 | -------------------------------------------------------------------------------- /Dangerfile: -------------------------------------------------------------------------------- 1 | # Reference: http://danger.systems/reference.html 2 | 3 | # A pull request summary is required. Add a description of the pull request purpose. 4 | # Changelog must be updated for each pull request that changes code. 5 | # Warnings will be issued for: 6 | # Pull request with more than 400 lines of code changed 7 | # Pull reqest that change more than 5 lines without test changes 8 | # Failures will be issued for: 9 | # Pull request without summary 10 | # Pull requests with code changes without changelog entry 11 | 12 | def code_changes? 13 | code = %w(libraries attributes recipes resources files templates) 14 | code.each do |location| 15 | return true unless git.modified_files.grep(/#{location}/).empty? 16 | end 17 | false 18 | end 19 | 20 | def test_changes? 21 | tests = %w(spec test kitchen.yml kitchen.dokken.yml) 22 | tests.each do |location| 23 | return true unless git.modified_files.grep(/#{location}/).empty? 24 | end 25 | false 26 | end 27 | 28 | failure 'Please provide a summary of your Pull Request.' if github.pr_body.length < 10 29 | 30 | warn 'This is a big Pull Request.' if git.lines_of_code > 400 31 | 32 | warn 'This is a Table Flip.' if git.lines_of_code > 2000 33 | 34 | # Require a CHANGELOG entry for non-test changes. 35 | if !git.modified_files.include?('CHANGELOG.md') && code_changes? 36 | failure 'Please include a CHANGELOG entry.' 37 | end 38 | 39 | # Require Major Minor Patch version labels 40 | unless github.pr_labels.grep /minor|major|patch/i 41 | warn 'Please add a release label to this pull request' 42 | end 43 | 44 | # A sanity check for tests. 45 | if git.lines_of_code > 5 && code_changes? && !test_changes? 46 | warn 'This Pull Request is probably missing tests.' 47 | end 48 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # logrotate Cookbook 2 | 3 | [![Cookbook Version](https://img.shields.io/cookbook/v/logrotate.svg)](https://supermarket.chef.io/cookbooks/logrotate) 4 | [![CI State](https://github.com/sous-chefs/logrotate/workflows/ci/badge.svg)](https://github.com/sous-chefs/logrotate/actions?query=workflow%3Aci) 5 | [![OpenCollective](https://opencollective.com/sous-chefs/backers/badge.svg)](#backers) 6 | [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) 7 | [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) 8 | 9 | Manages the logrotate package and provides resources to manage both global and application-specific logrotate configurations. This cookbook allows you to manage the logrotate package installation and create configuration for both the main logrotate.conf file and application-specific configurations in /etc/logrotate.d/. 10 | 11 | ## Maintainers 12 | 13 | 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. 14 | 15 | ## Requirements 16 | 17 | ### Platforms 18 | 19 | Should work on any platform that includes a 'logrotate' package and writes logrotate configuration to /etc/logrotate.d. 20 | 21 | Tested on: 22 | 23 | - Ubuntu / Debian 24 | - CentOS 25 | - Amazon Linux 26 | - openSUSE Leap 27 | 28 | ### Chef 29 | 30 | - Chef 15.3+ 31 | 32 | ## Resources 33 | 34 | - [logrotate_app](documentation/logrotate_app.md) - Manages application-specific logrotate configurations 35 | - [logrotate_global](documentation/logrotate_global.md) - Manages the global logrotate configuration 36 | - [logrotate_package](documentation/logrotate_package.md) - Manages the logrotate package installation 37 | 38 | ## Usage 39 | 40 | ### Package Installation 41 | 42 | By default, the cookbook will install the logrotate package: 43 | 44 | ```ruby 45 | logrotate_package 'logrotate' 46 | ``` 47 | 48 | ### Global Configuration 49 | 50 | To manage the global logrotate configuration: 51 | 52 | ```ruby 53 | logrotate_global 'logrotate' do 54 | options %w(weekly dateext) 55 | parameters( 56 | 'rotate' => 4, 57 | 'create' => nil 58 | ) 59 | paths( 60 | '/var/log/wtmp' => { 61 | 'missingok' => true, 62 | 'monthly' => true, 63 | 'create' => '0664 root utmp', 64 | 'rotate' => 1 65 | } 66 | ) 67 | end 68 | ``` 69 | 70 | ### Application-Specific Configuration 71 | 72 | To create application-specific logrotate configs, use the `logrotate_app` resource: 73 | 74 | ```ruby 75 | logrotate_app 'tomcat-myapp' do 76 | path '/var/log/tomcat/myapp.log' 77 | frequency 'daily' 78 | rotate 30 79 | create '644 root adm' 80 | options %w(missingok compress delaycompress copytruncate notifempty) 81 | end 82 | ``` 83 | 84 | For multiple log files: 85 | 86 | ```ruby 87 | logrotate_app 'tomcat-myapp' do 88 | path ['/var/log/tomcat/myapp.log', '/opt/local/tomcat/catalina.out'] 89 | frequency 'daily' 90 | create '644 root adm' 91 | rotate 7 92 | end 93 | ``` 94 | 95 | ## Contributors 96 | 97 | This project exists thanks to all the people who [contribute.](https://opencollective.com/sous-chefs/contributors.svg?width=890&button=false) 98 | 99 | ### Backers 100 | 101 | Thank you to all our backers! 102 | 103 | ![https://opencollective.com/sous-chefs#backers](https://opencollective.com/sous-chefs/backers.svg?width=600&avatarHeight=40) 104 | 105 | ### Sponsors 106 | 107 | Support this project by becoming a sponsor. Your logo will show up here with a link to your website. 108 | 109 | ![https://opencollective.com/sous-chefs/sponsor/0/website](https://opencollective.com/sous-chefs/sponsor/0/avatar.svg?avatarHeight=100) 110 | ![https://opencollective.com/sous-chefs/sponsor/1/website](https://opencollective.com/sous-chefs/sponsor/1/avatar.svg?avatarHeight=100) 111 | ![https://opencollective.com/sous-chefs/sponsor/2/website](https://opencollective.com/sous-chefs/sponsor/2/avatar.svg?avatarHeight=100) 112 | ![https://opencollective.com/sous-chefs/sponsor/3/website](https://opencollective.com/sous-chefs/sponsor/3/avatar.svg?avatarHeight=100) 113 | ![https://opencollective.com/sous-chefs/sponsor/4/website](https://opencollective.com/sous-chefs/sponsor/4/avatar.svg?avatarHeight=100) 114 | ![https://opencollective.com/sous-chefs/sponsor/5/website](https://opencollective.com/sous-chefs/sponsor/5/avatar.svg?avatarHeight=100) 115 | ![https://opencollective.com/sous-chefs/sponsor/6/website](https://opencollective.com/sous-chefs/sponsor/6/avatar.svg?avatarHeight=100) 116 | ![https://opencollective.com/sous-chefs/sponsor/7/website](https://opencollective.com/sous-chefs/sponsor/7/avatar.svg?avatarHeight=100) 117 | ![https://opencollective.com/sous-chefs/sponsor/8/website](https://opencollective.com/sous-chefs/sponsor/8/avatar.svg?avatarHeight=100) 118 | ![https://opencollective.com/sous-chefs/sponsor/9/website](https://opencollective.com/sous-chefs/sponsor/9/avatar.svg?avatarHeight=100) 119 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | Please refer to [the community cookbook documentation on testing](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/main/TESTING.MD). 4 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # to a Chef Infra Server or Supermarket. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | ehthumbs.db 9 | Icon? 10 | nohup.out 11 | Thumbs.db 12 | .envrc 13 | 14 | # EDITORS # 15 | ########### 16 | .#* 17 | .project 18 | .settings 19 | *_flymake 20 | *_flymake.* 21 | *.bak 22 | *.sw[a-z] 23 | *.tmproj 24 | *~ 25 | \#* 26 | REVISION 27 | TAGS* 28 | tmtags 29 | .vscode 30 | .editorconfig 31 | 32 | ## COMPILED ## 33 | ############## 34 | *.class 35 | *.com 36 | *.dll 37 | *.exe 38 | *.o 39 | *.pyc 40 | *.so 41 | */rdoc/ 42 | a.out 43 | mkmf.log 44 | 45 | # Testing # 46 | ########### 47 | .circleci/* 48 | .codeclimate.yml 49 | .delivery/* 50 | .foodcritic 51 | .kitchen* 52 | .mdlrc 53 | .overcommit.yml 54 | .rspec 55 | .rubocop.yml 56 | .travis.yml 57 | .watchr 58 | .yamllint 59 | azure-pipelines.yml 60 | Dangerfile 61 | examples/* 62 | features/* 63 | Guardfile 64 | kitchen*.yml 65 | mlc_config.json 66 | Procfile 67 | Rakefile 68 | spec/* 69 | test/* 70 | 71 | # SCM # 72 | ####### 73 | .git 74 | .gitattributes 75 | .gitconfig 76 | .github/* 77 | .gitignore 78 | .gitkeep 79 | .gitmodules 80 | .svn 81 | */.bzr/* 82 | */.git 83 | */.hg/* 84 | */.svn/* 85 | 86 | # Berkshelf # 87 | ############# 88 | Berksfile 89 | Berksfile.lock 90 | cookbooks/* 91 | tmp 92 | 93 | # Bundler # 94 | ########### 95 | vendor/* 96 | Gemfile 97 | Gemfile.lock 98 | 99 | # Policyfile # 100 | ############## 101 | Policyfile.rb 102 | Policyfile.lock.json 103 | 104 | # Documentation # 105 | ############# 106 | CODE_OF_CONDUCT* 107 | CONTRIBUTING* 108 | documentation/* 109 | TESTING* 110 | UPGRADING* 111 | 112 | # Vagrant # 113 | ########### 114 | .vagrant 115 | Vagrantfile 116 | -------------------------------------------------------------------------------- /documentation/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sous-chefs/logrotate/4c0c525b5f1eb26ef46b0de5bdecbad725fe71a7/documentation/.gitkeep -------------------------------------------------------------------------------- /documentation/logrotate_app.md: -------------------------------------------------------------------------------- 1 | # logrotate_app 2 | 3 | [Back to resource list](../README.md#resources) 4 | 5 | This resource can be used to drop off customized logrotate config files on a per application basis. 6 | 7 | The resource takes the following properties: 8 | 9 | ## Properties 10 | 11 | | Name | Type | Default | Description | 12 | | ---------------- | ------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- | 13 | | `path` | String, Array | `nil` | Specifies a single path (string) or multiple paths (array) that should have logrotation stanzas created in the config file. | 14 | | `cookbook` | String | `node['root_group']` | The cookbook that continues the template for logrotate_app config resources. | 15 | | `template_name` | String | `logrotate.erb` | Sets the template source. | 16 | | `template_mode` | String | `0644` | The mode to create the logrotate template. | 17 | | `template_owner` | String | `root` | The owner of the logrotate template. | 18 | | `template_group` | String | `root` | The group of the logrotate template. | 19 | | `frequency` | String | `weekly` | Sets the frequency for rotation. Valid values are: hourly, daily, weekly, monthly, yearly, see the logrotate man page for more information. | 20 | | `options` | String, Array | `%w(missingok compress delaycompress copytruncate notifempty)` | Any logrotate configuration option that doesn't specify a value. See the logrotate(8) manual page of v3.9.2 or earlier for details. | 21 | | `base_dir` | String | `/etc/logrotate.d` | The base directory where the logrotate configuration files will be stored. | 22 | | `firstaction` | String, Array | `nil` | Script to run before log files are rotated | 23 | | `prerotate` | String, Array | `nil` | Script to run before individual log file is rotated | 24 | | `postrotate` | String, Array | `nil` | Script to run after individual log file is rotated | 25 | | `lastaction` | String, Array | `nil` | Script to run after all log files are rotated | 26 | 27 | ## Examples 28 | 29 | In addition to the above properties, any logrotate option that takes a parameter can be used as a logrotate_app property. For example, to set the `rotate` option you can use a resource declaration such as: 30 | 31 | ```ruby 32 | logrotate_app 'tomcat-myapp' do 33 | path '/var/log/tomcat/myapp.log' 34 | frequency 'daily' 35 | rotate 30 36 | create '644 root adm' 37 | end 38 | ``` 39 | 40 | Also, any logrotate option that takes one of scripts names (`firstaction`, `prerotate`, `postrotate`, and `lastaction`) can be used. Script body should be passed as value of this option. For example, nginx logrotation with `postrotate`: 41 | 42 | ```ruby 43 | logrotate_app 'nginx' do 44 | path '/var/log/nginx/*.log' 45 | frequency 'daily' 46 | options %w(missingok compress delaycompress notifempty dateext dateyesterday nomail sharedscripts) 47 | rotate 365 48 | create '640 www-data www-data' 49 | dateformat '.%Y-%m-%d' 50 | maxage 365 51 | postrotate '[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`' 52 | end 53 | ``` 54 | 55 | See the logrotate(8) manual page of v3.9.2 or earlier for the list of available options. 56 | -------------------------------------------------------------------------------- /documentation/logrotate_global.md: -------------------------------------------------------------------------------- 1 | # logrotate_global 2 | 3 | [Back to resource list](../README.md#resources) 4 | 5 | This resource can be used to manage the global logrotate configuration file. 6 | 7 | The resource takes the following properties: 8 | 9 | ## Properties 10 | 11 | | Name | Type | Default | Description | 12 | | ---------------- | ------------- | ----------------------- | --------------------------------------------------------------- | 13 | | `config_file` | String | `'/etc/logrotate.conf'` | Specifies the path to the logrotate global config file. | 14 | | `template_name` | String | `logrotate-global.erb` | Sets the template source. | 15 | | `template_mode` | String | `0644` | The mode to create the logrotate config file template. | 16 | | `template_owner` | String | `root` | The owner of the logrotate config file template. | 17 | | `template_group` | String | `node['root_group']` | The group of the logrotate config file template. | 18 | | `cookbook` | String | `logrotate` | The cookbook that contains the template source. | 19 | | `options` | String, Array | `%w(weekly dateext)` | Logrotate global options. | 20 | | `includes` | String, Array | `[]` | Files or directories to include in the logrotate configuration. | 21 | | `parameters` | Hash | `{ 'rotate' => 4, 'create' => nil }` | Logrotate global parameters. | 22 | | `paths` | Hash | `{}` | Logrotate global path definitions. | 23 | | `scripts` | Hash | `{}` | Global scripts to run (firstaction, prerotate, postrotate, lastaction). | 24 | 25 | ## Examples 26 | 27 | ```ruby 28 | logrotate_global 'logrotate' do 29 | options %w(create weekly) 30 | parameters( 31 | 'rotate' => 4 32 | ) 33 | paths( 34 | '/var/log/wtmp' => { 35 | 'missingok' => true, 36 | 'monthly' => true, 37 | 'create' => '0664 root utmp', 38 | 'rotate' => 1, 39 | }, 40 | '/var/log/btmp' => { 41 | 'missingok' => true, 42 | 'monthly' => true, 43 | 'create' => '0600 root utmp', 44 | 'rotate' => 1, 45 | } 46 | ) 47 | end 48 | ``` 49 | 50 | See the logrotate(8) manual page of v3.9.2 or earlier for the list of available options. 51 | -------------------------------------------------------------------------------- /documentation/logrotate_package.md: -------------------------------------------------------------------------------- 1 | # logrotate_package 2 | 3 | [Back to resource list](../README.md#resources) 4 | 5 | Manages the installation of the logrotate package. This resource allows you to install, upgrade, or remove the logrotate package and its dependencies. 6 | 7 | Introduced: v3.0.0 8 | 9 | ## Actions 10 | 11 | - `:upgrade` - Upgrade the logrotate package if a newer version is available 12 | - `:install` - Install the logrotate package (default) 13 | - `:remove` - Remove the logrotate package 14 | 15 | ## Properties 16 | 17 | | Name | Type | Default | Description | 18 | | ---------- | ------------- | ------------- | ----------------------------------------- | 19 | | `packages` | String, Array | `'logrotate'` | Package name or array of package names to manage | 20 | 21 | ## Examples 22 | 23 | Basic installation using defaults: 24 | 25 | ```ruby 26 | logrotate_package 'logrotate' 27 | ``` 28 | 29 | Install a specific package: 30 | 31 | ```ruby 32 | logrotate_package 'logrotate' do 33 | packages 'logrotate-special-package' 34 | end 35 | ``` 36 | 37 | Install multiple packages: 38 | 39 | ```ruby 40 | logrotate_package 'logrotate' do 41 | packages ['logrotate', 'logrotate-dbg'] 42 | end 43 | ``` 44 | 45 | Upgrade existing installation: 46 | 47 | ```ruby 48 | logrotate_package 'logrotate' do 49 | action :upgrade 50 | end 51 | ``` 52 | 53 | Remove logrotate: 54 | 55 | ```ruby 56 | logrotate_package 'logrotate' do 57 | action :remove 58 | end 59 | -------------------------------------------------------------------------------- /kitchen.dokken.yml: -------------------------------------------------------------------------------- 1 | driver: 2 | name: dokken 3 | privileged: true 4 | chef_version: <%= ENV['CHEF_VERSION'] || 'current' %> 5 | 6 | transport: { name: dokken } 7 | provisioner: { name: dokken } 8 | 9 | platforms: 10 | - name: almalinux-8 11 | driver: 12 | image: dokken/almalinux-8 13 | pid_one_command: /usr/lib/systemd/systemd 14 | 15 | - name: almalinux-9 16 | driver: 17 | image: dokken/almalinux-9 18 | pid_one_command: /usr/lib/systemd/systemd 19 | 20 | - name: almalinux-10 21 | driver: 22 | image: dokken/almalinux-10 23 | pid_one_command: /usr/lib/systemd/systemd 24 | 25 | - name: amazonlinux-2023 26 | driver: 27 | image: dokken/amazonlinux-2023 28 | pid_one_command: /usr/lib/systemd/systemd 29 | 30 | - name: centos-stream-9 31 | driver: 32 | image: dokken/centos-stream-9 33 | pid_one_command: /usr/lib/systemd/systemd 34 | 35 | - name: centos-stream-10 36 | driver: 37 | image: dokken/centos-stream-10 38 | pid_one_command: /usr/lib/systemd/systemd 39 | 40 | - name: debian-11 41 | driver: 42 | image: dokken/debian-11 43 | pid_one_command: /bin/systemd 44 | 45 | - name: debian-12 46 | driver: 47 | image: dokken/debian-12 48 | pid_one_command: /bin/systemd 49 | 50 | - name: fedora-latest 51 | driver: 52 | image: dokken/fedora-latest 53 | pid_one_command: /usr/lib/systemd/systemd 54 | 55 | - name: opensuse-leap-15 56 | driver: 57 | image: dokken/opensuse-leap-15 58 | pid_one_command: /usr/lib/systemd/systemd 59 | 60 | - name: oraclelinux-8 61 | driver: 62 | image: dokken/oraclelinux-8 63 | pid_one_command: /usr/lib/systemd/systemd 64 | 65 | - name: oraclelinux-9 66 | driver: 67 | image: dokken/oraclelinux-9 68 | pid_one_command: /usr/lib/systemd/systemd 69 | 70 | - name: rockylinux-8 71 | driver: 72 | image: dokken/rockylinux-8 73 | pid_one_command: /usr/lib/systemd/systemd 74 | 75 | - name: rockylinux-9 76 | driver: 77 | image: dokken/rockylinux-9 78 | pid_one_command: /usr/lib/systemd/systemd 79 | 80 | - name: ubuntu-20.04 81 | driver: 82 | image: dokken/ubuntu-20.04 83 | pid_one_command: /bin/systemd 84 | 85 | - name: ubuntu-22.04 86 | driver: 87 | image: dokken/ubuntu-22.04 88 | pid_one_command: /bin/systemd 89 | 90 | - name: ubuntu-24.04 91 | driver: 92 | image: dokken/ubuntu-24.04 93 | pid_one_command: /bin/systemd 94 | -------------------------------------------------------------------------------- /kitchen.exec.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: { name: exec } 3 | transport: { name: exec } 4 | 5 | platforms: 6 | - name: macos-latest 7 | - name: windows-latest 8 | -------------------------------------------------------------------------------- /kitchen.global.yml: -------------------------------------------------------------------------------- 1 | --- 2 | provisioner: 3 | name: chef_infra 4 | product_name: chef 5 | product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> 6 | channel: stable 7 | install_strategy: once 8 | chef_license: accept 9 | enforce_idempotency: <%= ENV['ENFORCE_IDEMPOTENCY'] || true %> 10 | multiple_converge: <%= ENV['MULTIPLE_CONVERGE'] || 2 %> 11 | deprecations_as_errors: true 12 | log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> 13 | 14 | verifier: 15 | name: inspec 16 | 17 | platforms: 18 | - name: almalinux-8 19 | - name: almalinux-9 20 | - name: amazonlinux-2023 21 | - name: centos-stream-9 22 | - name: debian-11 23 | - name: debian-12 24 | - name: fedora-latest 25 | - name: opensuse-leap-15 26 | - name: oraclelinux-8 27 | - name: oraclelinux-9 28 | - name: rockylinux-8 29 | - name: rockylinux-9 30 | - name: ubuntu-20.04 31 | - name: ubuntu-22.04 32 | - name: ubuntu-24.04 33 | -------------------------------------------------------------------------------- /kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | provisioner: 6 | name: chef_infra 7 | deprecations_as_errors: true 8 | chef_license: accept-no-persist 9 | product_name: chef 10 | product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> 11 | install_strategy: once 12 | enforce_idempotency: true 13 | multiple_converge: 2 14 | 15 | verifier: 16 | name: inspec 17 | 18 | platforms: 19 | - name: almalinux-9 20 | - name: amazonlinux-2023 21 | - name: centos-stream-9 22 | - name: centos-stream-10 23 | - name: debian-11 24 | - name: debian-12 25 | - name: opensuse-leap-15 26 | - name: ubuntu-2204 27 | - name: ubuntu-2404 28 | 29 | suites: 30 | - name: default 31 | run_list: 32 | - recipe[test::default] 33 | -------------------------------------------------------------------------------- /libraries/logrotate.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: logrotate 3 | # Library:: logrotate 4 | # 5 | # Copyright:: 2013-2019, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | module Logrotate 21 | module Cookbook 22 | module LogrotateHelpers 23 | OPTIONS ||= %w(compress copy copytruncate daily dateext 24 | dateyesterday delaycompress hourly ifempty mailfirst maillast 25 | missingok monthly nocompress nocopy nocopytruncate nocreate nocreateolddir 26 | nodelaycompress nodateext nomail nomissingok noolddir 27 | nosharedscripts noshred notifempty renamecopy sharedscripts shred weekly 28 | yearly).freeze 29 | 30 | PARAMETERS ||= %w(compresscmd uncompresscmd compressext compressoptions 31 | create createolddir dateformat include mail extension maxage minsize maxsize 32 | rotate size shredcycles start tabooext su olddir).freeze 33 | 34 | SCRIPTS ||= %w(firstaction prerotate postrotate lastaction preremove).freeze 35 | 36 | PARAMETERS_AND_OPTIONS_AND_SCRIPTS ||= PARAMETERS + OPTIONS + SCRIPTS 37 | 38 | def parameters_from(hash) 39 | hash.sort.select { |k, _| PARAMETERS.include?(k) }.to_h 40 | end 41 | 42 | def options_from(values) 43 | values.select { |k, v| OPTIONS.include?(k) && v || v.nil? }.map { |k, _| k } 44 | end 45 | 46 | def paths_from(hash) 47 | hash.sort.select { |k, _| !PARAMETERS_AND_OPTIONS_AND_SCRIPTS.include?(k) }.map do |path, config| 48 | [path, { 'options' => options_from(config), 'parameters' => parameters_from(config), 'scripts' => scripts_from(config) }] 49 | end.to_h 50 | end 51 | 52 | def scripts_from(hash) 53 | hash.sort.select { |k, _| SCRIPTS.include?(k) }.map do |script, lines| 54 | [script, lines.respond_to?(:join) ? lines.join("\n") : lines] 55 | end.to_h 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /libraries/template.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: logrotate 3 | # Library:: template 4 | # 5 | # Copyright:: 2013-2019, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | module Logrotate 21 | module Cookbook 22 | module TemplateHelpers 23 | def nil_or_empty?(*values) 24 | values.any? { |v| v.nil? || (v.respond_to?(:empty?) && v.empty?) } 25 | end 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name 'logrotate' 2 | maintainer 'Sous Chefs' 3 | maintainer_email 'help@sous-chefs.org' 4 | license 'Apache-2.0' 5 | description 'Installs logrotate package and provides a resource for managing logrotate configs' 6 | version '3.0.29' 7 | source_url 'https://github.com/sous-chefs/logrotate' 8 | issues_url 'https://github.com/sous-chefs/logrotate/issues' 9 | chef_version '>= 15.3' 10 | 11 | supports 'amazon' 12 | supports 'centos' 13 | supports 'fedora' 14 | supports 'oracle' 15 | supports 'redhat' 16 | supports 'scientific' 17 | supports 'ubuntu' 18 | -------------------------------------------------------------------------------- /renovate.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json", 3 | "extends": ["config:base"], 4 | "packageRules": [ 5 | { 6 | "groupName": "Actions", 7 | "matchUpdateTypes": ["minor", "patch", "pin"], 8 | "automerge": true, 9 | "addLabels": ["Release: Patch", "Skip: Announcements"] 10 | }, 11 | { 12 | "groupName": "Actions", 13 | "matchUpdateTypes": ["major"], 14 | "automerge": false, 15 | "addLabels": ["Release: Patch", "Skip: Announcements"] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /resources/app.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: logrotate 3 | # Resource:: app 4 | # 5 | # Copyright:: 2016-2019, Steven Danna 6 | # Copyright:: 2009-2019, Chef Software, Inc. 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | # 20 | 21 | unified_mode true 22 | 23 | include ::Logrotate::Cookbook::LogrotateHelpers 24 | 25 | property :path, [String, Array], 26 | coerce: proc { |p| Array(p).sort.map { |path| path.to_s.inspect }.join(' ') } 27 | 28 | property :frequency, String, 29 | default: 'weekly' 30 | 31 | property :cookbook, String, 32 | default: 'logrotate' 33 | 34 | property :template_name, String, 35 | default: 'logrotate.erb' 36 | 37 | property :template_mode, String, 38 | default: '0644' 39 | 40 | property :template_owner, String, 41 | default: 'root' 42 | 43 | property :template_group, String, 44 | default: 'root' 45 | 46 | property :base_dir, String, 47 | default: '/etc/logrotate.d' 48 | 49 | property :options, [String, Array], 50 | default: %w(missingok compress delaycompress copytruncate notifempty), 51 | coerce: proc { |p| options_from(p.is_a?(Array) ? p : p.split) } 52 | 53 | ::Logrotate::Cookbook::LogrotateHelpers::SCRIPTS.each { |script_name| property(script_name.to_sym, coerce: proc { |p| Array(p).join("\n ") }) } 54 | 55 | ::Logrotate::Cookbook::LogrotateHelpers::PARAMETERS.each { |configurable_name| property(configurable_name.to_sym) } 56 | 57 | action_class do 58 | include ::Logrotate::Cookbook::LogrotateHelpers 59 | 60 | def required_properties_set? 61 | raise Chef::Exceptions::ValidationFailed, 'path is a required property' unless action.eql?(:delete) || !new_resource.path.nil? 62 | end 63 | 64 | def handle_parameters(new_resource) 65 | ::Logrotate::Cookbook::LogrotateHelpers::PARAMETERS.map do |parameter_name| 66 | [ parameter_name, new_resource.send(parameter_name.to_sym) ] if new_resource.send(parameter_name.to_sym) 67 | end.compact.to_h 68 | end 69 | 70 | def handle_scripts(new_resource) 71 | ::Logrotate::Cookbook::LogrotateHelpers::SCRIPTS.map do |script_name| 72 | [ script_name, new_resource.send(script_name.to_sym) ] if new_resource.send(script_name.to_sym) 73 | end.compact.to_h 74 | end 75 | end 76 | 77 | action :enable do 78 | required_properties_set? 79 | 80 | directory new_resource.base_dir do 81 | owner 'root' 82 | group node['root_group'] 83 | mode '0755' 84 | action :create 85 | end 86 | 87 | template "#{new_resource.base_dir}/#{new_resource.name}" do 88 | cookbook new_resource.cookbook 89 | source new_resource.template_name 90 | 91 | mode new_resource.template_mode 92 | owner new_resource.template_owner 93 | group new_resource.template_group 94 | 95 | sensitive new_resource.sensitive 96 | 97 | variables( 98 | path: new_resource.path, 99 | frequency: new_resource.frequency, 100 | options: new_resource.options, 101 | scripts: handle_scripts(new_resource), 102 | parameters: handle_parameters(new_resource) 103 | ) 104 | 105 | helpers(Logrotate::Cookbook::TemplateHelpers) 106 | 107 | action :create 108 | end 109 | end 110 | 111 | action :disable do 112 | file "#{new_resource.base_dir}/#{new_resource.name}" do 113 | action :delete 114 | end 115 | end 116 | -------------------------------------------------------------------------------- /resources/global.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: logrotate 3 | # Resource:: global 4 | # 5 | # Copyright:: 2009-2019, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | unified_mode true 21 | 22 | include ::Logrotate::Cookbook::LogrotateHelpers 23 | 24 | property :config_file, String, 25 | default: '/etc/logrotate.conf' 26 | 27 | property :template_owner, String, 28 | default: 'root' 29 | 30 | property :template_group, String, 31 | default: lazy { node['root_group'] } 32 | 33 | property :template_mode, String, 34 | default: '0644' 35 | 36 | property :cookbook, String, 37 | default: 'logrotate' 38 | 39 | property :template_name, String, 40 | default: 'logrotate-global.erb' 41 | 42 | property :options, [String, Array], 43 | default: %w(weekly dateext), 44 | coerce: proc { |p| options_from(p.is_a?(Array) ? p : p.split) } 45 | 46 | property :includes, [String, Array], 47 | default: [], 48 | coerce: proc { |p| p.is_a?(Array) ? p : p.split } 49 | 50 | property :parameters, Hash, 51 | default: { 'rotate' => 4, 'create' => nil }, 52 | coerce: proc { |p| parameters_from(p) } 53 | 54 | property :paths, Hash, 55 | default: {}, 56 | coerce: proc { |p| paths_from(p) } 57 | 58 | property :scripts, Hash, 59 | default: {}, 60 | coerce: proc { |p| scripts_from(p) } 61 | 62 | action :create do 63 | template new_resource.config_file do 64 | cookbook new_resource.cookbook 65 | source new_resource.template_name 66 | 67 | owner new_resource.template_owner 68 | group new_resource.template_group 69 | mode new_resource.template_mode 70 | 71 | sensitive new_resource.sensitive 72 | 73 | variables( 74 | includes: new_resource.includes, 75 | options: new_resource.options, 76 | parameters: new_resource.parameters, 77 | paths: new_resource.paths, 78 | scripts: new_resource.scripts 79 | ) 80 | 81 | helpers(Logrotate::Cookbook::TemplateHelpers) 82 | 83 | action :create 84 | end 85 | end 86 | 87 | action :delete do 88 | file new_resource.config_file do 89 | action :delete 90 | end 91 | end 92 | -------------------------------------------------------------------------------- /resources/package.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook:: logrotate 3 | # Resource:: app 4 | # 5 | # Copyright:: 2009-2019, Chef Software, Inc. 6 | # 7 | # Licensed under the Apache License, Version 2.0 (the "License"); 8 | # you may not use this file except in compliance with the License. 9 | # You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, software 14 | # distributed under the License is distributed on an "AS IS" BASIS, 15 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | # See the License for the specific language governing permissions and 17 | # limitations under the License. 18 | # 19 | 20 | unified_mode true 21 | 22 | property :packages, [String, Array], 23 | default: 'logrotate' 24 | 25 | action_class do 26 | def do_package_action(action) 27 | package 'logrotate' do 28 | package_name new_resource.packages 29 | action action 30 | end 31 | end 32 | end 33 | 34 | %i(upgrade install remove).each { |action_type| send(:action, action_type) { do_package_action(action) } } 35 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | RSpec.configure do |config| 5 | config.color = true # Use color in STDOUT 6 | config.formatter = :documentation # Use the specified formatter 7 | config.log_level = :error # Avoid deprecation notice SPAM 8 | end 9 | -------------------------------------------------------------------------------- /spec/unit/resources/app_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'logrotate_global' do 4 | step_into :logrotate_resources 5 | platform 'centos' 6 | 7 | recipe do 8 | include_recipe 'test::app' 9 | end 10 | 11 | context 'tomcat-myapp' do 12 | it 'creates appropriate logrotate config' do 13 | expect(chef_run).to enable_logrotate_app('tomcat-myapp').with( 14 | create: '644 root adm', 15 | frequency: 'daily', 16 | path: '"/var/log/tomcat/myapp.log"', 17 | rotate: 30 18 | ) 19 | end 20 | end 21 | 22 | context 'tomcat-myapp-multi-path' do 23 | it 'creates appropriate logrotate config' do 24 | expect(chef_run).to enable_logrotate_app('tomcat-myapp-multi-path').with( 25 | create: '644 root adm', 26 | frequency: 'daily', 27 | path: '"/opt/local/tomcat/catalina.out" "/var/log/tomcat/myapp-multi-path.log"', 28 | rotate: 7 29 | ) 30 | end 31 | end 32 | 33 | context 'tomcat-myapp-no-enable' do 34 | it 'does not create appropriate logrotate config' do 35 | expect(chef_run).not_to enable_logrotate_app('tomcat-myapp-no-enable') 36 | end 37 | end 38 | 39 | context 'tomcat-myapp-custom-options' do 40 | it 'creates appropriate logrotate config' do 41 | expect(chef_run).to enable_logrotate_app('tomcat-myapp-custom-options').with( 42 | create: '644 root adm', 43 | frequency: 'daily', 44 | path: '"/var/log/tomcat/myapp-custom-options.log"', 45 | rotate: 30, 46 | options: %w(missingok delaycompress), 47 | firstaction: 'echo "hi"' 48 | ) 49 | end 50 | end 51 | 52 | context 'tomcat-myapp-sharedscripts' do 53 | it 'creates appropriate logrotate config' do 54 | expect(chef_run).to enable_logrotate_app('tomcat-myapp-sharedscripts').with( 55 | options: %w(missingok compress delaycompress copytruncate notifempty sharedscripts), 56 | path: '"/var/log/tomcat/myapp-sharedscripts.log"' 57 | ) 58 | end 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /spec/unit/resources/global_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'logrotate_global' do 4 | step_into :logrotate_global 5 | platform 'centos' 6 | 7 | recipe do 8 | logrotate_global 'logrotate' do 9 | options %w(create weekly) 10 | parameters( 11 | 'rotate' => 4 12 | ) 13 | paths( 14 | '/var/log/wtmp' => { 15 | 'missingok' => true, 16 | 'monthly' => true, 17 | 'create' => '0664 root utmp', 18 | 'rotate' => 1, 19 | }, 20 | '/var/log/btmp' => { 21 | 'missingok' => true, 22 | 'monthly' => true, 23 | 'create' => '0600 root utmp', 24 | 'rotate' => 1, 25 | } 26 | ) 27 | end 28 | end 29 | 30 | it 'writes the configuration template' do 31 | is_expected.to render_file('/etc/logrotate.conf') 32 | .with_content(/rotate 4/) 33 | .with_content(/weekly/) 34 | .with_content(%r{\/var\/log\/wtmp \{}) 35 | .with_content(/ create 0664 root utmp/) 36 | .with_content(/ missingok/) 37 | .with_content(/ monthly/) 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /spec/unit/resources/package_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'logrotate_package' do 4 | step_into :logrotate_package 5 | platform 'centos' 6 | 7 | context 'installs the logrotate package' do 8 | recipe do 9 | logrotate_package '' 10 | end 11 | 12 | describe 'creates a systemd unit file' do 13 | it { is_expected.to upgrade_package('logrotate') } 14 | end 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /templates/logrotate-global.erb: -------------------------------------------------------------------------------- 1 | # 2 | # Generated by Chef for <%= node['fqdn'] %> 3 | # Do NOT modify this file by hand, changes will be overwritten. 4 | # 5 | <% unless nil_or_empty?(@options) %> 6 | 7 | # Options 8 | <% @options.each do |opt| -%> 9 | <%= opt %> 10 | <% end -%> 11 | <% end -%> 12 | <% unless nil_or_empty?(@parameters) %> 13 | 14 | # Parameters 15 | <% @parameters.each do |p, v| -%> 16 | <%= p %><% unless nil_or_empty?(v) %> <%= v %><% end -%> 17 | <% end -%> 18 | <% end -%> 19 | <% unless nil_or_empty?(@scripts) %> 20 | 21 | # Scripts 22 | <% @scripts.each do | scripttype, body | -%> 23 | <%= scripttype %> 24 | <%= body %> 25 | endscript 26 | <% end -%> 27 | <% end -%> 28 | 29 | # Includes 30 | include /etc/logrotate.d 31 | <% unless nil_or_empty?(@includes) %> 32 | 33 | <% @includes.each do |inc| -%> 34 | include <%= inc %> 35 | <% end -%> 36 | <% end -%> 37 | <% unless nil_or_empty?(@paths) %> 38 | 39 | # Paths 40 | <% @paths.each do |path, config| -%> 41 | <%= path %> { 42 | <% unless nil_or_empty?(config['options']) %> 43 | # Options 44 | <% config['options'].each do |opt|-%> 45 | <%= opt %> 46 | <% end -%> 47 | <% end -%> 48 | <% unless nil_or_empty?(config['parameters']) %> 49 | 50 | # Parameters 51 | <% config['parameters'].each do |k, v| -%> 52 | <%= k %> <%= v %> 53 | <% end -%> 54 | <% end -%> 55 | <% unless nil_or_empty?(config['scripts']) %> 56 | 57 | # Scripts 58 | <% config['scripts'].each do |type, body| -%> 59 | <%= type %> 60 | <%= body %> 61 | endscript 62 | <% end -%> 63 | <% end -%> 64 | } 65 | 66 | <% end -%> 67 | <% end -%> 68 | -------------------------------------------------------------------------------- /templates/logrotate.erb: -------------------------------------------------------------------------------- 1 | # This file was generated by Chef. 2 | # Do not modify this file by hand! 3 | 4 | <%= @path %> { 5 | <% unless nil_or_empty?(@frequency) -%> 6 | <%= @frequency %> 7 | <% end -%> 8 | <% unless nil_or_empty?(@parameters) -%> 9 | <% @parameters.each do |name, value| -%> 10 | <%= "#{name} #{value}" %> 11 | <% end -%> 12 | <% end -%> 13 | <% unless nil_or_empty?(@options) -%> 14 | <% @options.each do |opt| -%> 15 | <%= opt %> 16 | <% end -%> 17 | <% end -%> 18 | <% unless nil_or_empty?(@scripts) -%> 19 | <% @scripts.each do |name, script| -%> 20 | <%= name %> 21 | <%= script %> 22 | endscript 23 | <% end -%> 24 | <% end -%> 25 | } 26 | -------------------------------------------------------------------------------- /test/cookbooks/test/metadata.rb: -------------------------------------------------------------------------------- 1 | name 'test' 2 | version '1.0.0' 3 | license 'Apache-2.0' 4 | depends 'logrotate' 5 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/app.rb: -------------------------------------------------------------------------------- 1 | logrotate_app 'tomcat-myapp' do 2 | path '/var/log/tomcat/myapp.log' 3 | frequency 'daily' 4 | rotate 30 5 | create '644 root adm' 6 | end 7 | 8 | logrotate_app 'tomcat-myapp-multi-path' do 9 | path %w(/var/log/tomcat/myapp-multi-path.log /opt/local/tomcat/catalina.out) 10 | frequency 'daily' 11 | create '644 root adm' 12 | rotate 7 13 | end 14 | 15 | logrotate_app 'tomcat-myapp-no-enable' do 16 | path '/var/log/tomcat/myapp-no-enable.log' 17 | frequency 'daily' 18 | rotate 30 19 | action :disable 20 | end 21 | 22 | logrotate_app 'tomcat-myapp-custom-options' do 23 | path '/var/log/tomcat/myapp-custom-options.log' 24 | options %w(missingok delaycompress) 25 | frequency 'daily' 26 | rotate 30 27 | create '644 root adm' 28 | firstaction 'echo "hi"' 29 | end 30 | 31 | logrotate_app 'tomcat-myapp-custom-options-as-string' do 32 | path '/var/log/tomcat/myapp-custom-options-as-string.log' 33 | options 'missingok delaycompress' 34 | frequency 'daily' 35 | rotate 30 36 | create '644 root adm' 37 | firstaction 'echo "hi"' 38 | end 39 | 40 | logrotate_app 'tomcat-myapp-custom-template' do 41 | path '/var/log/tomcat/myapp-custom-template.log' 42 | cookbook 'test' 43 | options 'missingok delaycompress' 44 | frequency 'daily' 45 | rotate 30 46 | create '644 root adm' 47 | firstaction 'echo "hi"' 48 | end 49 | 50 | logrotate_app 'tomcat-myapp-sharedscripts' do 51 | path '/var/log/tomcat/myapp-sharedscripts.log' 52 | options 'missingok compress delaycompress copytruncate notifempty sharedscripts' 53 | end 54 | 55 | logrotate_app 'tomcat-myapp-multi-script' do 56 | path '/var/log/tomcat/myapp-multi-script.log' 57 | postrotate [ 58 | '/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true', 59 | '/bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true', 60 | ] 61 | end 62 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/default.rb: -------------------------------------------------------------------------------- 1 | logrotate_package '' 2 | 3 | 2.times { |t| file "/var/log/global_log_#{t}" } 4 | 5 | include_recipe '::global' 6 | include_recipe '::app' 7 | -------------------------------------------------------------------------------- /test/cookbooks/test/recipes/global.rb: -------------------------------------------------------------------------------- 1 | logrotate_global 'logrotate' do 2 | options %w(create weekly dateext) 3 | parameters( 4 | 'rotate' => 4 5 | ) 6 | paths( 7 | '/var/log/global_log_0' => { 8 | 'missingok' => true, 9 | 'monthly' => true, 10 | 'create' => '0664 root utmp', 11 | 'rotate' => 1, 12 | }, 13 | '/var/log/global_log_1' => { 14 | 'missingok' => true, 15 | 'monthly' => true, 16 | 'create' => '0600 root utmp', 17 | 'rotate' => 1, 18 | } 19 | ) 20 | end 21 | -------------------------------------------------------------------------------- /test/cookbooks/test/templates/logrotate.erb: -------------------------------------------------------------------------------- 1 | # 2 | # This is a custom template! 3 | # This is the interface we support, if it isn't here, 4 | # don't depend on it being available 5 | # 6 | 7 | <%= @path %> { 8 | <%- if @frequency %> 9 | <%= @frequency %> 10 | <%- end %> 11 | <%- @parameters.each do |name, value| %> 12 | <%= "#{name} #{value}" %> 13 | <%- end %> 14 | <% @options.each do |o| -%> 15 | <%= o %> 16 | <% end -%> 17 | <%- @scripts.each do |script_name, script| %> 18 | <%= script_name %> 19 | <%= script %> 20 | endscript 21 | <%- end %> 22 | } 23 | -------------------------------------------------------------------------------- /test/integration/default/global_spec.rb: -------------------------------------------------------------------------------- 1 | describe package('logrotate') do 2 | it { should be_installed } 3 | end 4 | 5 | describe file('/etc/logrotate.conf') do 6 | it { should be_a_file } 7 | its('mode') { should cmp '0644' } 8 | its('content') { should include 'include /etc/logrotate.d' } 9 | its('content') { should include ' missingok' } 10 | its('content') { should include ' monthly' } 11 | end 12 | 13 | describe file('/etc/logrotate.d') do 14 | it { should be_a_directory } 15 | its('mode') { should cmp '0755' } 16 | end 17 | -------------------------------------------------------------------------------- /test/integration/default/resources_spec.rb: -------------------------------------------------------------------------------- 1 | describe file('/etc/logrotate.d/tomcat-myapp') do 2 | it { should be_a_file } 3 | its('mode') { should cmp '0644' } 4 | its('content') { should match(%r("/var/log/tomcat/myapp.log" {\s*daily\s*create 644 root adm\s*rotate 30)) } 5 | end 6 | 7 | describe file('/etc/logrotate.d/tomcat-myapp-multi-path') do 8 | it { should be_a_file } 9 | its('mode') { should cmp '0644' } 10 | its('content') { should match(%r("/opt/local/tomcat/catalina.out" "/var/log/tomcat/myapp-multi-path.log" {\s*daily\s*create 644 root adm\s*rotate 7)) } 11 | end 12 | 13 | describe file('/etc/logrotate.d/tomcat-myapp-no-enable') do 14 | it { should_not be_a_file } 15 | end 16 | 17 | describe file('/etc/logrotate.d/tomcat-myapp-custom-options') do 18 | it { should be_a_file } 19 | its('mode') { should cmp '0644' } 20 | its('content') { should include 'missingok' } 21 | its('content') { should include 'delaycompress' } 22 | its('content') { should include 'firstaction' } 23 | end 24 | 25 | describe file('/etc/logrotate.d/tomcat-myapp-custom-options-as-string') do 26 | it { should be_a_file } 27 | its('mode') { should cmp '0644' } 28 | its('content') { should include 'missingok' } 29 | its('content') { should include 'delaycompress' } 30 | its('content') { should include 'firstaction' } 31 | end 32 | 33 | describe file('/etc/logrotate.d/tomcat-myapp-custom-template') do 34 | it { should be_a_file } 35 | its('mode') { should cmp '0644' } 36 | its('content') { should include '# This is a custom template!' } 37 | its('content') { should include 'missingok' } 38 | its('content') { should include 'delaycompress' } 39 | its('content') { should include 'firstaction' } 40 | end 41 | 42 | describe file('/etc/logrotate.d/tomcat-myapp-sharedscripts') do 43 | it { should be_a_file } 44 | its('mode') { should cmp '0644' } 45 | its('content') { should include 'sharedscripts' } 46 | end 47 | 48 | describe file('/etc/logrotate.d/tomcat-myapp-multi-script') do 49 | it { should be_a_file } 50 | its('mode') { should cmp '0644' } 51 | postrotate_content = [ 52 | ' postrotate', 53 | ' /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true', 54 | ' /bin/kill -HUP `cat /var/run/rsyslogd.pid 2> /dev/null` 2> /dev/null || true', 55 | ' endscript', 56 | ] 57 | its('content') { should match /#{postrotate_content.join("\n")}/ } 58 | end 59 | 60 | describe command('logrotate /etc/logrotate.conf') do 61 | its('exit_status') { should eq 0 } 62 | end 63 | --------------------------------------------------------------------------------