From: Fernando Date: Wed, 19 Mar 2025 00:07:00 +0000 (-0600) Subject: Modifying the structure of the script to create log rotation configuration for openvp... X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=8d9ae414fab914e3c24e41074cda2d6a6dc71394;p=ceph-cm-ansible.git Modifying the structure of the script to create log rotation configuration for openvpn logs. Adding trap command to do a cleanup in case of failure. Changing the name in the module that creates log rotate configuration script. --- diff --git a/roles/gateway/files/openvpn_weekly_rotation b/roles/gateway/files/openvpn_weekly_rotation index aafa9af..bf5fe2b 100644 --- a/roles/gateway/files/openvpn_weekly_rotation +++ b/roles/gateway/files/openvpn_weekly_rotation @@ -5,13 +5,14 @@ LOG_FILE="openvpn.log" ARCHIVE_DIR="/var/log/openvpn/weekly-logs" WEEKLY_ARCHIVE_NAME="openvpn-$(date +\%Y-\%m-\%d)_weekly_logs.tar.gz" RETENTION_DAYS=365 # Keep weekly archives for a year +TEMP_DIR=$(mktemp -d) # Temporary folder for decompressed logs + +# Clean the temporary folder in case of failure +trap 'rm -rf "$TEMP_DIR"' ERR # Create archive directory if it doesn't exist mkdir -p "$ARCHIVE_DIR" -# Temporary folder for decompressed logs -TEMP_DIR=$(mktemp -d) - # Decompress all rotated daily logs (mylogfile.log.1.gz, mylogfile.log.2.gz, etc.) for file in $(find "$LOG_DIR" -name "$LOG_FILE-*"); do gzip -d -c $file > "$TEMP_DIR/$(basename $file .gz)"; diff --git a/roles/gateway/tasks/logging.yml b/roles/gateway/tasks/logging.yml index 87be5d2..e2ed11a 100644 --- a/roles/gateway/tasks/logging.yml +++ b/roles/gateway/tasks/logging.yml @@ -13,7 +13,7 @@ dest: /etc/logrotate.d/openvpn notify: restart rsyslog -- name: Write weekly rotation script on anacron +- name: Create weekly log rotation script copy: src: files/openvpn_weekly_rotation dest: /etc/cron.weekly/openvpn_weekly_rotation