Skip to content

Commit

Permalink
Use Wildfly user crontab to compress general and GC logs
Browse files Browse the repository at this point in the history
configuration option is: wildfly_log_compress_local_user
  • Loading branch information
KAMI911 committed Jan 30, 2024
1 parent 017e6ef commit c7603d7
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,20 @@ both the size and timestamp of a log file are considered.
Location is the compressor program. Default is xz so the dafault value is '/usr/bin/xz'.
You can also use for example: '/usr/bin/gzip'.

wildfly_log_compress_options: '-9e'
wildfly_log_compress_options: '-3'

Options for compression program. For xz the default is '-9e' that means maximum compression.
Options for compression program. For xz the default is '-3' that means a fast compression.
For gzip íou can use for example: '-9'.

wildfly_log_compress_extension: '.xz'

File extension for logrotate specification. xz is '.xz', and gzip is 'gz'.

wildfly_log_compress_local_user: false

Set false to use cron.d for compressing Wildfly general logs and GC logs (default), or
set true to use Wildfly user's crontab to do compression.

## Dependencies

None.
Expand Down
1 change: 1 addition & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,4 @@ wildfly_log_rotate_minsize: 20K
wildfly_log_compress_command: '/usr/bin/xz'
wildfly_log_compress_options: '-3 -T4'
wildfly_log_compress_extension: '.xz'
wildfly_log_compress_local_user: false
56 changes: 55 additions & 1 deletion tasks/configure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,61 @@
owner: "root"
group: "root"
mode: "0644"
when: cron_d_dir.stat.exists
when:
- cron_d_dir.stat.exists
- not wildfly_log_compress_local_user

- block:
- name: "prepare daily log compress domain mode Wildfly local user's crontab task with direcrory grouping"
ansible.builtin.cron:
user: '{{ wildfly_user }}'
name: "check dirs"
minute: "10"
hour: "2"
job: 'nice -n 10 find {{ wildfly_directory_grouping_log }}/servers/ \( -name \*????-??-??.log -or -name \*log.????-??-?? \) ! \( -name \*.xz -or -name \*.gz -or -name \*.zip -or -name \*.tgz \) -mtime +1 -type f -print0 | xargs -0 -t -r {{ wildfly_log_compress_command }} {{ wildfly_log_compress_options }}'
- name: "prepare daily GC log compress domain mode Wildfly local user's crontab task with direcrory grouping"
ansible.builtin.cron:
user: '{{ wildfly_user }}'
name: "check dirs"
minute: "10"
hour: "2"
job: 'nice -n 10 find {{ wildfly_gc_dir }}/ \( -name gc[_-]\*.log -or -name gc[_-]\*.log.\? -or -name gc[_-]\*.log.\?? -or -name gc[_-]\*.log.\??? \) ! \( -name \*.xz -or -name \*.gz -or -name \*.zip -or -name \*.tgz \) -mtime +1 -type f -print0 | xargs -0 -t -r {{ wildfly_log_compress_command }} -S .`date +\%Y\%m\%d_\%H\%M`.xz {{ wildfly_log_compress_options }}'
when:
- wildfly_log_compress_local_user
- wildfly_role == 'domain-slave' or wildfly_role == 'domain-master-slave'
- wildfly_directory_grouping_by_type is true and wildfly_directory_grouping_log is defined and wildfly_directory_grouping_log

- block:
- name: "prepare daily log compress domain mode Wildfly local user's crontab task"
ansible.builtin.cron:
user: '{{ wildfly_user }}'
name: "check dirs"
minute: "10"
hour: "2"
job: 'nice -n 10 find {{ wildfly_directory_grouping_log }}/servers/ \( -name \*????-??-??.log -or -name \*log.????-??-?? \) ! \( -name \*.xz -or -name \*.gz -or -name \*.zip -or -name \*.tgz \) -mtime +1 -type f -print0 | xargs -0 -t -r {{ wildfly_log_compress_command }} {{ wildfly_log_compress_options }}'
- name: "prepare daily GC log compress domain mode Wildfly local user's crontab task"
ansible.builtin.cron:
user: '{{ wildfly_user }}'
name: "check dirs"
minute: "10"
hour: "2"
job: 'nice -n 10 find {{ wildfly_gc_dir }}/ \( -name gc[_-]\*.log -or -name gc[_-]\*.log.\? -or -name gc[_-]\*.log.\?? -or -name gc[_-]\*.log.\??? \) ! \( -name \*.xz -or -name \*.gz -or -name \*.zip -or -name \*.tgz \) -mtime +1 -type f -print0 | xargs -0 -t -r {{ wildfly_log_compress_command }} -S .`date +\%Y\%m\%d_\%H\%M`.xz {{ wildfly_log_compress_options }}'
when:
- wildfly_log_compress_local_user
- wildfly_role == 'domain-slave' or wildfly_role == 'domain-master-slave'
- not (wildfly_directory_grouping_by_type is true and wildfly_directory_grouping_log is defined and wildfly_directory_grouping_log)

- block:
- name: "prepare daily log compress for standalonw Wildfly local user's crontab task"
ansible.builtin.cron:
user: '{{ wildfly_user }}'
name: "check dirs"
minute: "10"
hour: "2"
job: 'nice -n 10 find {{ wildfly_base }}/standalone/log/ \( -name \*????-??-??.log -or -name \*log.????-??-?? \) ! \( -name \*.xz -or -name \*.gz -or -name \*.zip -or -name \*.tgz \) -mtime +1 -type f -print0 | xargs -0 -t -r {{ wildfly_log_compress_command }} {{ wildfly_log_compress_options }}'
when:
- wildfly_log_compress_local_user
- wildfly_role == 'standalone'

- include: configure-properties.yml

Expand Down

0 comments on commit c7603d7

Please sign in to comment.