logrotate: better rotation options

The extant "logrotate_daily" varaible doesn't really do anything and
isn't used.  Modify this to be able to set a range of rotation periods
or a size.

Update mirror rsync mirrors to rotate weekly, as often releases run
overnight and it's a pain to reconstruct.

Change-Id: I121dc5f4fe7f226b66d18b9ec39e7e3839be4d40
This commit is contained in:
Ian Wienand 2019-09-18 14:31:33 +10:00
parent 64e5f9235d
commit d4a96a421b
5 changed files with 32 additions and 5 deletions

View File

@ -36,8 +36,20 @@ not an exhaustive list of directives (contributions are welcome).
.. zuul:rolevar:: logrotate_rotate
:default: 7
.. zuul:rolevar:: logrotate_daily
:default: yes
.. zuul:rolevar:: logrotate_frequency
:default: daily
One of ``hourly``, ``daily``, ``weekly``, ``monthly``, ``yearly``
or ``size``.
If choosing ``size``, :zuul:rolevar::`logrotate.logrotate_size` must
be specified
.. zuul:rolevar:: logrotate_size
:default: None
Size; e.g. 100K, 10M, 1G. Only when
:zuul:rolevar::`logrotate.logrotate_frequency` is ``size``.
.. zuul:rolevar:: logrotate_notifempty
:default: yes

View File

@ -3,5 +3,6 @@ logrotate_copytruncate: yes
logrotate_delaycompress: yes
logrotate_missingok: yes
logrotate_rotate: 7
logrotate_daily: yes
logrotate_frequency: daily
logrotate_size: None
logrotate_notifempty: yes

View File

@ -3,6 +3,17 @@
msg: Must set logrotate_file_name for logfile to rotate
when: logrotate_file_name is not defined
- assert:
that:
- logrotate_frequency in ('hourly', 'daily', 'weekly', 'monthly', 'yearly', 'size')
fail_msg: Invalid logrotate_frequency
- assert:
that:
- logrotate_size
fail_msg: Must specify size for rotation
when: logrotate_frequency == 'size'
# Hash the full path to avoid any conflicts but remain idempotent.
# "/var/log/ansible/ansible.log" becomes "ansible.log.37237.conf" for example
- name: Create a unique config name

View File

@ -12,8 +12,10 @@
missingok
{% endif %}
rotate {{ logrotate_rotate }}
{% if logrotate_daily %}
daily
{% if logrotate_frequency != "size" %}
{{ logrotate_frequency }}
{% else %}
size {{ logrotate_size }}
{% endif %}
{% if logrotate_notifempty %}
notifempty

View File

@ -53,4 +53,5 @@
name: logrotate
vars:
logrotate_file_name: '/var/log/rsync-mirrors/{{ item }}.log'
logrotate_frequency: 'weekly'
loop: '{{ rsync_update_scripts }}'