https://github.com/joedborg/charm-logrotate-reactive
Provides log rotation for services on a unit
https://github.com/joedborg/charm-logrotate-reactive
Last synced: 8 months ago
JSON representation
Provides log rotation for services on a unit
- Host: GitHub
- URL: https://github.com/joedborg/charm-logrotate-reactive
- Owner: joedborg
- License: apache-2.0
- Created: 2018-12-11T16:07:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-12-12T15:31:33.000Z (over 7 years ago)
- Last Synced: 2025-10-13T02:43:11.736Z (8 months ago)
- Language: Python
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Overview
This charm provides a simple way for charms to add log rotation or
for an admin to rotate files not otherwise managed.
## Admin-Controlled Usage
If you want to rotate un-managed files, this is what you want.
You will still need to add a relation to one of your existing services
(it will use the juju-info interface), as this is a subordinate charm,
but logrotate will not interact with that service (just files that happen
to share the same unit).
There is a per-logfile config setting:
**logfiles** Provides local logfile settings or overrides package or
charmed log rotation.
As there could be many variations, the logfiles setting is a JSON-format
string, set out as follows:
`{"first_logfile_name":{"path":"/path/to/logs/*.log", "option":"value", ...}}`
Where *option* can be any of the above settings plus two additional
ones: *prerotate* and *postrotate* which supply pre- and post-rotation commands.
Per-logfile options will override the default settings.
To manage more than one file, just extend the logfiles string:
`{"logfile1": {}, "logfile2", {}}`
## Charm-Controlled Usage
It is also possible for a charm to manage its own log rotation using
the logrotate subordinate charm. A "logrotate" interface is provided
for this.
Used like this, you can still have manually-managed log rotation - these
will be added to whatever the related charm configures.
Passing the above "logfiles" JSON string in the charm's relation
data from a logrotate-relation-changed hook should be all that's needed.
For example:
```
from charmhelpers.core.hookenv import relation_set, relation_id, relation_ids
def update_logrotate():
relation_data = {}
relation_data["logfiles"] = '{"apache2":{"path":"/var/log/apache2/*.log","when":"daily","period":"7"}}'
if relation_id():
relation_set(None, relation_data)
else:
for r in relation_ids("logrotate"):
relation_set(r, relation_data)
```
## Notes
Charm-controlled log-rotation through the logrotate interface can be
overridden by a matching entry in the *logfiles* config option. For
example, if a charm sets weekly rotation on "mylogfiles" using the
logrotate relation interface:
`relation_data["logfiles"] = '{"mylogfiles":{"path":"/var/log/mycharm/*.log","when":"weekly"}}'`
But the admin wants them rotated daily, they just need to:
`juju config logrotate logfiles='{"mylogfiles":{"path":"/var/log/mycharm/*.log","when":"daily"}}'`
# Example
```
juju deploy apache2
juju deploy logrotate
juju config logrotate logfiles='{"apache2":{"path":"/var/log/apache2/*.log","when":"daily","period":"28"}}'
juju add-relation apache2 logrotate
```