forked from ISTI-ansible-roles/ansible-roles
ghn-gcore-maintenance: add a cron job that removes the old logs. See https://support.d4science.org/issues/11522
This commit is contained in:
parent
35a5e9d95b
commit
1705b75589
|
@ -1,6 +1,9 @@
|
|||
---
|
||||
gcore_maintenance_restart_cron: False
|
||||
gcore_maintenance_log_files_cleanup: True
|
||||
gcore_maintenance_log_files_cleanup_script: '/usr/local/bin/clean_access_log'
|
||||
|
||||
gcore_weekday_cron_run: '*'
|
||||
gcore_maintenance_cron_users:
|
||||
- { user: '{{ d4science_user }}', weekday: "*", job: "echo '`date`' >/home/{{ d4science_user }}/gcore_service_restart.log ; /home/{{ d4science_user }}/stopContainer.sh >>/home/{{ d4science_user }}/gcore_service_restart.log 2>&1 ; sleep 30 ; /home/{{ d4science_user }}/startContainer.sh >>/home/{{ d4science_user }}/gcore_service_restart.log 2>&1" }
|
||||
- { user: '{{ d4science_user }}', weekday: "{{ gcore_weekday_cron_run }}", job: "echo '`date`' >{{ d4science_user_home }}/gcore_service_restart.log ; {{ d4science_user_home }}/stopContainer.sh >>{{ d4science_user_home }}/gcore_service_restart.log 2>&1 ; sleep 30 ; {{ d4science_user_home }}/startContainer.sh >>{{ d4science_user_home }}/gcore_service_restart.log 2>&1", logrotate_job: '{{ gcore_maintenance_log_files_cleanup_script }}' }
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
|
||||
RETVAL=
|
||||
cd "$HOME/gCore/logs"
|
||||
RETVAL=$?
|
||||
if [ $RETVAL -ne 0 ] ; then
|
||||
logger "The $HOME/gCore/logs does not exist, exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
gzip -v9 access.log.????-??-??
|
||||
|
||||
/bin/ls -1t access.log.????-??-??.gz | tail -n +91 | xargs rm -v
|
||||
|
||||
exit 0
|
||||
|
|
@ -29,3 +29,33 @@
|
|||
|
||||
when: not gcore_maintenance_restart_cron
|
||||
tags: [ 'gcoreboot', 'gcore_cron' ]
|
||||
|
||||
- block:
|
||||
- name: Install the log cleanup script
|
||||
copy: src=clean_access_log.sh dest={{ gcore_maintenance_log_files_cleanup_script }} mode=0755 owner=root group=root
|
||||
|
||||
- name: Install a cron job that removes the old log files
|
||||
cron: name="Cleanup the {{ item.user }} gCore log files"
|
||||
special_time='daily'
|
||||
user="{{ item.user }}"
|
||||
job="{{ item.logrotate_job }}"
|
||||
disabled="{{ item.disabled | default(False) }}"
|
||||
with_items: '{{ gcore_maintenance_cron_users }}'
|
||||
when: item.logrotate_job is defined
|
||||
|
||||
when: gcore_maintenance_log_files_cleanup
|
||||
tags: [ 'gcoreboot', 'gcore_cron', 'gcore_logs' ]
|
||||
|
||||
- block:
|
||||
- name: Remove the cron job that restarts the registry gCore service
|
||||
cron: name="Cleanup the {{ item.user }} gCore log files"
|
||||
special_time='daily'
|
||||
user="{{ item.user }}"
|
||||
job="{{ item.logrotate_job }}"
|
||||
disabled="{{ item.disabled | default(False) }}"
|
||||
state=absent
|
||||
with_items: '{{ gcore_maintenance_cron_users }}'
|
||||
when: item.logrotate_job is defined
|
||||
|
||||
when: not gcore_maintenance_log_files_cleanup
|
||||
tags: [ 'gcoreboot', 'gcore_cron', 'gcore_logs' ]
|
||||
|
|
Loading…
Reference in New Issue