Elasticsearch: daily job for log rotation

This commit is contained in:
Jérémy Lecour 2017-11-14 11:07:06 +01:00 committed by Jérémy Lecour
parent bcbfcf9080
commit 4746354c54
4 changed files with 21 additions and 0 deletions

View File

@ -8,6 +8,7 @@ elasticsearch_custom_tmpdir: Null
elasticsearch_default_tmpdir: /var/lib/elasticsearch/tmp
elasticsearch_jvm_xms: 2g
elasticsearch_jvm_xmx: 2g
elasticsearch_log_rotate_days: 365
elasticsearch_curator: False

View File

@ -0,0 +1,9 @@
---
- name: "log rotation script"
template:
src: rotate_elasticsearch_logs.j2
dest: /etc/cron.daily/rotate_elasticsearch_logs
owner: root
group: root
mode: "0750"

View File

@ -10,6 +10,8 @@
- include: tmpdir.yml
- include: logs.yml
- include: plugin_head.yml
when: elasticsearch_plugin_head

View File

@ -0,0 +1,9 @@
#!/bin/sh
# {{ ansible_managed }}
LOG_DIR=/var/log/elasticsearch
USER=elasticsearch
MAX_AGE={{ elasticsearch_log_rotate_days | mandatory }}
find ${LOG_DIR} -type f -user ${USER} -name "*.log.????-??-??" -exec gzip --best {} \;
find ${LOG_DIR} -type f -user ${USER} -name "*.log.????-??-??.gz" -mtime +${MAX_AGE} -delete