From 1705b75589ae8c92a02acaf00592a6c58acf8942 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 10 Dec 2018 19:24:55 +0100 Subject: [PATCH] ghn-gcore-maintenance: add a cron job that removes the old logs. See https://support.d4science.org/issues/11522 --- .../ghn-gcore-maintenance/defaults/main.yml | 5 +++- .../files/clean_access_log.sh | 16 ++++++++++ .../ghn-gcore-maintenance/tasks/main.yml | 30 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 ghn-gcore/ghn-gcore-maintenance/files/clean_access_log.sh diff --git a/ghn-gcore/ghn-gcore-maintenance/defaults/main.yml b/ghn-gcore/ghn-gcore-maintenance/defaults/main.yml index bbef5b57..ef93eea0 100644 --- a/ghn-gcore/ghn-gcore-maintenance/defaults/main.yml +++ b/ghn-gcore/ghn-gcore-maintenance/defaults/main.yml @@ -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 }}' } diff --git a/ghn-gcore/ghn-gcore-maintenance/files/clean_access_log.sh b/ghn-gcore/ghn-gcore-maintenance/files/clean_access_log.sh new file mode 100644 index 00000000..c3c910c4 --- /dev/null +++ b/ghn-gcore/ghn-gcore-maintenance/files/clean_access_log.sh @@ -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 + diff --git a/ghn-gcore/ghn-gcore-maintenance/tasks/main.yml b/ghn-gcore/ghn-gcore-maintenance/tasks/main.yml index 52b49976..abc254c1 100644 --- a/ghn-gcore/ghn-gcore-maintenance/tasks/main.yml +++ b/ghn-gcore/ghn-gcore-maintenance/tasks/main.yml @@ -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' ]