From bc45d97fd63ef594a5b083b8723575f81d61016e Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Mon, 6 Jan 2025 09:07:36 +0000 Subject: [PATCH 1/2] Update and fix documentation Signed-off-by: Dan Webb --- .github/workflows/ci.yml | 18 +++++----- .rubocop.yml | 2 ++ README.md | 57 ++++++++++++++++++++---------- documentation/logrotate_app.md | 19 ++++++---- documentation/logrotate_global.md | 19 +++++----- documentation/logrotate_package.md | 37 ++++++++++++++++--- resources/global.rb | 2 +- 7 files changed, 103 insertions(+), 51 deletions(-) create mode 100644 .rubocop.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 28b136c..89a02a2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,24 +23,22 @@ jobs: strategy: matrix: os: - - "almalinux-8" - - "amazonlinux-2" - - "centos-7" - - "centos-stream-8" - - "debian-10" + - "almalinux-9" + - "amazonlinux-2023" + - "centos-stream-9" + - "centos-stream-10" - "debian-11" - - "fedora-latest" + - "debian-12" - "opensuse-leap-15" - - "rockylinux-8" - - "ubuntu-1804" - - "ubuntu-2004" + - "ubuntu-2204" + - "ubuntu-2404" suite: - "default" fail-fast: false steps: - name: Check out code - uses: actions/checkout@v4 # v4 + uses: actions/checkout@v4 - name: Install Chef uses: actionshub/chef-install@3.0.0 - name: Dokken diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..6188300 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +require: + - cookstyle diff --git a/README.md b/README.md index 7444a9e..c7fdc4d 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![OpenCollective](https://opencollective.com/sous-chefs/sponsors/badge.svg)](#sponsors) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) -Manages the logrotate package and provides a resource to manage application specific logrotate configuration. +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/. ## Maintainers @@ -27,49 +27,68 @@ Tested on: ### Chef -- Chef 12.5+ +- Chef 15.3+ ## Resources -- [logrotate_app](documentation/logrotate_app.md) -- [logrotate_global](documentation/logrotate_global.md) -- [logrotate_package](documentation/logrotate_package.md) +- [logrotate_app](documentation/logrotate_app.md) - Manages application-specific logrotate configurations +- [logrotate_global](documentation/logrotate_global.md) - Manages the global logrotate configuration +- [logrotate_package](documentation/logrotate_package.md) - Manages the logrotate package installation ## Usage -The package resource will ensure logrotate is always up to date by default. +### Package Installation -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`: +By default, the cookbook will install the logrotate package: ```ruby -logrotate_app 'tomcat-myapp' do - path '/var/log/tomcat/myapp.log' - frequency 'daily' - rotate 30 - create '644 root adm' +logrotate_package 'logrotate' +``` + +### Global Configuration + +To manage the global logrotate configuration: + +```ruby +logrotate_global 'logrotate' do + options %w(weekly dateext) + parameters( + 'rotate' => 4, + 'create' => nil + ) + paths( + '/var/log/wtmp' => { + 'missingok' => true, + 'monthly' => true, + 'create' => '0664 root utmp', + 'rotate' => 1 + } + ) end ``` -To rotate multiple logfile paths, specify the path as an array: +### Application-Specific Configuration + +To create application-specific logrotate configs, use the `logrotate_app` resource: ```ruby logrotate_app 'tomcat-myapp' do - path ['/var/log/tomcat/myapp.log', '/opt/local/tomcat/catalina.out'] + path '/var/log/tomcat/myapp.log' frequency 'daily' + rotate 30 create '644 root adm' - rotate 7 + options %w(missingok compress delaycompress copytruncate notifempty) end ``` -To specify which logrotate options, specify the options as an array: +For multiple log files: ```ruby logrotate_app 'tomcat-myapp' do - path '/var/log/tomcat/myapp.log' - options ['missingok', 'delaycompress', 'notifempty'] + path ['/var/log/tomcat/myapp.log', '/opt/local/tomcat/catalina.out'] frequency 'daily' - rotate 30 create '644 root adm' + rotate 7 end ``` diff --git a/documentation/logrotate_app.md b/documentation/logrotate_app.md index 80a5b63..954e8e7 100644 --- a/documentation/logrotate_app.md +++ b/documentation/logrotate_app.md @@ -11,13 +11,18 @@ The resource takes the following properties: | Name | Type | Default | Description | | ---------------- | ------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | `path` | String, Array | `nil` | Specifies a single path (string) or multiple paths (array) that should have logrotation stanzas created in the config file. | -| `cookbook` | String | `logrotate` | The cookbook that continues the template for logrotate_app config resources. | -| `template_name` | String | `logrotate` | Sets the template source. | -| `template_mode` | String | `logrotate` | The mode to create the logrotate template. | -| `template_owner` | String | `logrotate` | The owner of the logrotate template. | -| `template_group` | String | `logrotate` | The group of the logrotate template. | -| `frequency` | String | `logrotate` | Sets the frequency for rotation. Valid values are: hourly, daily, weekly, monthly, yearly, see the logrotate man page for more information. | -| `options` | String | `logrotate` | Any logrotate configuration option that doesn't specify a value. See the logrotate(8) manual page of v3.9.2 or earlier for details. | +| `cookbook` | String | `node['root_group']` | The cookbook that continues the template for logrotate_app config resources. | +| `template_name` | String | `logrotate.erb` | Sets the template source. | +| `template_mode` | String | `0644` | The mode to create the logrotate template. | +| `template_owner` | String | `root` | The owner of the logrotate template. | +| `template_group` | String | `root` | The group of the logrotate template. | +| `frequency` | String | `weekly` | Sets the frequency for rotation. Valid values are: hourly, daily, weekly, monthly, yearly, see the logrotate man page for more information. | +| `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. | +| `base_dir` | String | `/etc/logrotate.d` | The base directory where the logrotate configuration files will be stored. | +| `firstaction` | String, Array | `nil` | Script to run before log files are rotated | +| `prerotate` | String, Array | `nil` | Script to run before individual log file is rotated | +| `postrotate` | String, Array | `nil` | Script to run after individual log file is rotated | +| `lastaction` | String, Array | `nil` | Script to run after all log files are rotated | ## Examples diff --git a/documentation/logrotate_global.md b/documentation/logrotate_global.md index 1b77497..c793f9b 100644 --- a/documentation/logrotate_global.md +++ b/documentation/logrotate_global.md @@ -2,7 +2,7 @@ [Back to resource list](../README.md#resources) -This resource can be used to drop off customized logrotate config files on a per application basis. +This resource can be used to manage the global logrotate configuration file. The resource takes the following properties: @@ -10,16 +10,17 @@ The resource takes the following properties: | Name | Type | Default | Description | | ---------------- | ------------- | ----------------------- | --------------------------------------------------------------- | -| `config_file` | String, | `'/etc/logrotate.conf'` | Specifies the path to the logrotate global config file. | +| `config_file` | String | `'/etc/logrotate.conf'` | Specifies the path to the logrotate global config file. | | `template_name` | String | `logrotate-global.erb` | Sets the template source. | -| `template_mode` | String | `logrotate` | The mode to create the logrotate config file template. | -| `template_owner` | String | `logrotate` | The owner of the logrotate config file template. | -| `template_group` | String | `logrotate` | The group of the logrotate config file template. | -| `options` | String, Array | `['weekly', 'datext']` | Logrotate global options. | +| `template_mode` | String | `0644` | The mode to create the logrotate config file template. | +| `template_owner` | String | `root` | The owner of the logrotate config file template. | +| `template_group` | String | `node['root_group']` | The group of the logrotate config file template. | +| `cookbook` | String | `logrotate` | The cookbook that contains the template source. | +| `options` | String, Array | `%w(weekly dateext)` | Logrotate global options. | | `includes` | String, Array | `[]` | Files or directories to include in the logrotate configuration. | -| `parameters` | Hash | `{}` | Logrotate global parameters. | -| `path` | Hash | `{}` | Logrotate global path definitions. | -| `scripts` | Hash | `{}` | Logrotate global options. | +| `parameters` | Hash | `{ 'rotate' => 4, 'create' => nil }` | Logrotate global parameters. | +| `paths` | Hash | `{}` | Logrotate global path definitions. | +| `scripts` | Hash | `{}` | Global scripts to run (firstaction, prerotate, postrotate, lastaction). | ## Examples diff --git a/documentation/logrotate_package.md b/documentation/logrotate_package.md index 508b7de..15aeb57 100644 --- a/documentation/logrotate_package.md +++ b/documentation/logrotate_package.md @@ -2,30 +2,57 @@ [Back to resource list](../README.md#resources) -Install logrotate from package. +Manages the installation of the logrotate package. This resource allows you to install, upgrade, or remove the logrotate package and its dependencies. Introduced: v3.0.0 ## Actions -- `:install` -- `:upgrade` -- `:remove` +- `:upgrade` - Upgrade the logrotate package if a newer version is available +- `:install` - Install the logrotate package (default) +- `:remove` - Remove the logrotate package ## Properties | Name | Type | Default | Description | | ---------- | ------------- | ------------- | ----------------------------------------- | -| `packages` | String, Array | `'logrotate'` | List of packages to install for logrotate | +| `packages` | String, Array | `'logrotate'` | Package name or array of package names to manage | ## Examples +Basic installation using defaults: + ```ruby logrotate_package 'logrotate' ``` +Install a specific package: + ```ruby logrotate_package 'logrotate' do packages 'logrotate-special-package' end ``` + +Install multiple packages: + +```ruby +logrotate_package 'logrotate' do + packages ['logrotate', 'logrotate-dbg'] +end +``` + +Upgrade existing installation: + +```ruby +logrotate_package 'logrotate' do + action :upgrade +end +``` + +Remove logrotate: + +```ruby +logrotate_package 'logrotate' do + action :remove +end diff --git a/resources/global.rb b/resources/global.rb index 9ecdbe8..2365ad6 100644 --- a/resources/global.rb +++ b/resources/global.rb @@ -28,7 +28,7 @@ default: 'root' property :template_group, String, - default: 'root' + default: lazy { node['root_group'] } property :template_mode, String, default: '0644' From 625536985d8ab57fb03c367df550f39b2b74b5b6 Mon Sep 17 00:00:00 2001 From: Dan Webb Date: Mon, 6 Jan 2025 11:58:47 +0000 Subject: [PATCH 2/2] SQUASHME Signed-off-by: Dan Webb --- .github/workflows/ci.yml | 3 +- CHANGELOG.md | 89 ++++++++++++++++++++++------------------ kitchen.yml | 26 +++++------- 3 files changed, 61 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89a02a2..9517805 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: - "centos-stream-10" - "debian-11" - "debian-12" - - "opensuse-leap-15" + # - "opensuse-leap-15" - "ubuntu-2204" - "ubuntu-2404" suite: @@ -46,6 +46,7 @@ jobs: env: CHEF_LICENSE: accept-no-persist KITCHEN_LOCAL_YAML: kitchen.dokken.yml + CHEF_VERSION: ${{ vars.CHEF_VERSION }} with: suite: ${{ matrix.suite }} os: ${{ matrix.os }} diff --git a/CHANGELOG.md b/CHANGELOG.md index f7e0c7c..89c6160 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,44 +8,54 @@ This file is used to list changes made in each version of the logrotate cookbook Standardise files with files in sous-chefs/repo-management -Standardise files with files in sous-chefs/repo-management - ## 3.0.26 - *2024-07-15* Standardise files with files in sous-chefs/repo-management -Standardise files with files in sous-chefs/repo-management - -Standardise files with files in sous-chefs/repo-management - ## 3.0.25 - *2024-05-06* +No notable changes + ## 3.0.24 - *2024-05-06* +No notable changes + ## 3.0.23 - *2023-09-28* +No notable changes + ## 3.0.22 - *2023-09-04* +No notable changes + ## 3.0.21 - *2023-07-10* +No notable changes + ## 3.0.20 - *2023-05-17* +No notable changes + ## 3.0.19 - *2023-04-07* Standardise files with files in sous-chefs/repo-management ## 3.0.18 - *2023-04-01* +No notable changes + ## 3.0.17 - *2023-04-01* -## 3.0.16 - *2023-04-01* +No notable changes -Standardise files with files in sous-chefs/repo-management +## 3.0.16 - *2023-04-01* Standardise files with files in sous-chefs/repo-management ## 3.0.15 - *2023-03-02* +No notable changes + ## 3.0.14 - *2023-02-27* Standardise files with files in sous-chefs/repo-management @@ -64,39 +74,37 @@ Standardise files with files in sous-chefs/repo-management Standardise files with files in sous-chefs/repo-management -Standardise files with files in sous-chefs/repo-management - ## 3.0.9 - *2022-02-17* -- Standardise files with files in sous-chefs/repo-management +Standardise files with files in sous-chefs/repo-management ## 3.0.8 - *2022-02-08* -- Remove delivery folder +Remove delivery folder ## 3.0.7 - *2022-02-01* -- Update tested platforms +Update tested platforms ## 3.0.6 - *2022-01-14* -- Do not sort options as the order can be important +Do not sort options as the order can be important ## 3.0.5 - *2021-11-03* -- Add CentOS Stream 8 to CI pipeline +Add CentOS Stream 8 to CI pipeline ## 3.0.4 - *2021-08-30* -- Standardise files with files in sous-chefs/repo-management +Standardise files with files in sous-chefs/repo-management ## 3.0.3 - *2021-06-01* -- Standardise files with files in sous-chefs/repo-management +Standardise files with files in sous-chefs/repo-management ## 3.0.2 - *2021-05-12* -- Fix passing options to global path declarations +Fix passing options to global path declarations ## 3.0.1 - *2021-05-12* @@ -218,46 +226,45 @@ Standardise files with files in sous-chefs/repo-management - Fix missing end tag in template - Don't re-initialize constants. - Fix rubocop finding -- [COOK-3911] Allow to use maxsize parameter. -- [COOK-4000] Allow to use dateyesterday option. -- [COOK-4024] Allow to use su parameter. -- [COOK-4175] Allows use of the dateformat parameter. +- Allow to use maxsize parameter. +- Allow to use dateyesterday option. +- Allow to use su parameter. +- Allows use of the dateformat parameter. - Loosen test-kitchen version constraint - Add rvm files to gitignore ## 1.4.0 -- **[COOK-3632](https://tickets.chef.io/browse/COOK-3632)** - Raise Exception when adding more than one invalid option -- **[COOK-3141](https://tickets.chef.io/browse/COOK-3141)** - Do not duplicate template entires for multiple paths -- **[COOK-3034](https://tickets.chef.io/browse/COOK-3034)** - Update logrotate_app params to accept arrays and strings -- **[COOK-2646](https://tickets.chef.io/browse/COOK-2646)** - Add ability to choose file mode for logrotate template +- Raise Exception when adding more than one invalid option +- Do not duplicate template entires for multiple paths +- Update logrotate_app params to accept arrays and strings +- Add ability to choose file mode for logrotate template ## 1.3.0 -- **[COOK-3341](https://tickets.chef.io/browse/COOK-3341)** - Add optional `frequency` and `rotate` params when defined globally -- **[COOK-3298](https://tickets.chef.io/browse/COOK-3298)** - Use `Array` instead of `respond_to?(:each)` -- **[COOK-3285](https://tickets.chef.io/browse/COOK-3285)** - Change `logrotate.d` config file mode to `0644` -- **[COOK-3250](https://tickets.chef.io/browse/COOK-3250)** - Add `minsize` -- **[COOK-3274](https://tickets.chef.io/browse/COOK-3274)** - Fix README typo that suggested the opposite action - -- **[COOK-2923](https://tickets.chef.io/browse/COOK-2923)** - Add `olddir` option -- **[COOK-1651](https://tickets.chef.io/browse/COOK-1651)** - Add `dateext` ability +- Add optional `frequency` and `rotate` params when defined globally +- Use `Array` instead of `respond_to?(:each)` +- Change `logrotate.d` config file mode to `0644` +- Add `minsize` +- Fix README typo that suggested the opposite action +- Add `olddir` option +- Add `dateext` ability ## 1.2.2 -- [COOK-2872]: Add firstaction/lastaction ability to logrotate -- [COOK-2908]: Argument error in `logrotate_app` definition +- Add firstaction/lastaction ability to logrotate +- Argument error in `logrotate_app` definition ## 1.2.0 -- [COOK-2401] - Add the ability to manage the global logrotate configuration +- Add the ability to manage the global logrotate configuration ## 1.1.0 -- [COOK-2218] - Logrotate size parameter +- Logrotate size parameter ## 1.0.2 -- [COOK-1027] - Add support for pre-/post-rotate commands -- [COOK-1338] - Update log rotate for more flexibility of rotate options -- [COOK-1598] - "Create" isn't a mandatory option +- Add support for pre-/post-rotate commands +- Update log rotate for more flexibility of rotate options +- "Create" isn't a mandatory option diff --git a/kitchen.yml b/kitchen.yml index 2022c09..75f81f8 100644 --- a/kitchen.yml +++ b/kitchen.yml @@ -5,30 +5,26 @@ driver: provisioner: name: chef_infra deprecations_as_errors: true - enforce_idempotency: true - multiple_converge: 2 - chef_license: accept + chef_license: accept-no-persist product_name: chef product_version: <%= ENV['CHEF_VERSION'] || 'latest' %> - install_strategy: always - log_level: <%= ENV['CHEF_LOG_LEVEL'] || 'auto' %> - + install_strategy: once + enforce_idempotency: true + multiple_converge: 2 verifier: name: inspec platforms: - - name: almalinux-8 - - name: amazonlinux-2 - - name: centos-7 - - name: centos-stream-8 - - name: debian-10 + - name: almalinux-9 + - name: amazonlinux-2023 + - name: centos-stream-9 + - name: centos-stream-10 - name: debian-11 - - name: fedora-latest + - name: debian-12 - name: opensuse-leap-15 - - name: ubuntu-18.04 - - name: ubuntu-20.04 - - name: rockylinux-8 + - name: ubuntu-2204 + - name: ubuntu-2404 suites: - name: default