Skip to content

Commit

Permalink
Update and fix documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Webb <[email protected]>
  • Loading branch information
damacus committed Jan 6, 2025
1 parent 6437442 commit bc45d97
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 51 deletions.
18 changes: 8 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
- name: Dokken
Expand Down
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require:
- cookstyle
57 changes: 38 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
```

Expand Down
19 changes: 12 additions & 7 deletions documentation/logrotate_app.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 10 additions & 9 deletions documentation/logrotate_global.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

[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:

## 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

Expand Down
37 changes: 32 additions & 5 deletions documentation/logrotate_package.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion resources/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
default: 'root'

property :template_group, String,
default: 'root'
default: lazy { node['root_group'] }

property :template_mode, String,
default: '0644'
Expand Down

0 comments on commit bc45d97

Please sign in to comment.