From ecd8ab838339764ea606eac1e8edcd2ab4cc4b06 Mon Sep 17 00:00:00 2001 From: Nils Philippsen Date: Sep 09 2021 10:38:38 +0000 Subject: Merge syncing and combining logs into one cronjob This should prevent race conditions of the form that logs are attempted to be combined while syncing those of individual hosts hasn't finished. Signed-off-by: Nils Philippsen --- diff --git a/roles/web-data-analysis/files/combineHttp.cron b/roles/web-data-analysis/files/combineHttp.cron deleted file mode 100644 index 016a796..0000000 --- a/roles/web-data-analysis/files/combineHttp.cron +++ /dev/null @@ -1 +0,0 @@ -0 06 * * * root /usr/local/bin/combineHttpLogs.sh diff --git a/roles/web-data-analysis/files/sync-http-logs-and-merge.sh b/roles/web-data-analysis/files/sync-http-logs-and-merge.sh new file mode 100755 index 0000000..888ae82 --- /dev/null +++ b/roles/web-data-analysis/files/sync-http-logs-and-merge.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +# Don't attempt to combine if syncing the individual logs failed. +set -e + +/usr/local/bin/sync-http-logs.py +/usr/local/bin/combineHttpLogs.sh diff --git a/roles/web-data-analysis/tasks/main.yml b/roles/web-data-analysis/tasks/main.yml index bd1379b..b44814c 100644 --- a/roles/web-data-analysis/tasks/main.yml +++ b/roles/web-data-analysis/tasks/main.yml @@ -178,13 +178,22 @@ - name: install a script to sync httpd logs via cron only on log01 copy: src: sync-http-logs.py - dest: /etc/cron.daily/sync-http-logs.py + dest: /usr/local/bin/sync-http-logs.py mode: 0755 when: inventory_hostname.startswith('log01') tags: - web-data - cron +- name: remove sync-http-logs.py from cron.daily directory + file: + path: /etc/cron.daily/sync-http-logs.py + state: absent + when: inventory_hostname.startswith('log01') + tags: + - web-data + - cron + - name: install awstats package package: state=present name=awstats tags: @@ -202,8 +211,19 @@ - config - web-data -- name: daily cron job to merge old logs - copy: src=combineHttp.cron dest=/etc/cron.d/ mode=0644 +- name: remove separate daily cron job to merge old logs + file: + path: /etc/cron.d/combineHttp.cron + state: absent tags: + - web-data - cron + +- name: install daily cron job to sync and merge log files + copy: + src: sync-http-logs-and-merge.sh + dest: /etc/cron.d + mode: 0755 + tags: - web-data + - cron