From 08844d618b018431546ab0ef279f4b3a8a842f99 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Tue, 17 Mar 2026 10:24:50 +0100 Subject: [PATCH 01/10] YDA-6868: add archiving configuration --- roles/matomo_docker/defaults/main.yml | 31 ++++++++++++++ roles/matomo_docker/tasks/archiving.yml | 41 +++++++++++++++++++ roles/matomo_docker/tasks/main.yml | 5 +++ .../templates/logrotate-matomo-archive.j2 | 9 ++++ .../templates/matomo-archive.sh.j2 | 25 +++++++++++ 5 files changed, 111 insertions(+) create mode 100644 roles/matomo_docker/tasks/archiving.yml create mode 100644 roles/matomo_docker/templates/logrotate-matomo-archive.j2 create mode 100644 roles/matomo_docker/templates/matomo-archive.sh.j2 diff --git a/roles/matomo_docker/defaults/main.yml b/roles/matomo_docker/defaults/main.yml index de9ca60..4f7f9b9 100644 --- a/roles/matomo_docker/defaults/main.yml +++ b/roles/matomo_docker/defaults/main.yml @@ -34,3 +34,34 @@ matomo_mail_from_address: matomo@changeme.nl matomo_cert_mode: selfsigned matomo_static_cert: notset matomo_static_cert_key: notset + +# Matomo CLI pre-archiving +# Enable scheduled CLI archiving +matomo_archiving_enabled: true + +# Docker container name running Matomo +matomo_docker_container_name: matomo + +# Matomo console path inside the container +matomo_console_path: /var/www/html/matomo/console + +# Host paths for script/log/lock +matomo_archive_script_path: /usr/local/bin/matomo-archive +matomo_archive_log_dir: /var/log/matomo +matomo_archive_log_file: "{{ matomo_archive_log_dir }}/archive.log" +matomo_archive_lock_file: /run/matomo-archive.lock + +# Cron schedule (default: hourly at minute 15) +matomo_archive_cron_minute: "15" +matomo_archive_cron_hour: "*" +matomo_archive_cron_day: "*" +matomo_archive_cron_month: "*" +matomo_archive_cron_weekday: "*" + +# Extra args for `core:archive` (use "-vvv" temporarily for debugging) +matomo_archive_extra_args: "-q" + +# Logrotate policy +matomo_archive_logrotate_enabled: true +matomo_archive_logrotate_frequency: daily +matomo_archive_logrotate_rotate: 14 diff --git a/roles/matomo_docker/tasks/archiving.yml b/roles/matomo_docker/tasks/archiving.yml new file mode 100644 index 0000000..bd6de2a --- /dev/null +++ b/roles/matomo_docker/tasks/archiving.yml @@ -0,0 +1,41 @@ +--- +- name: "Ensure log directory exists" + ansible.builtin.file: + path: "{{ matomo_archive_log_dir }}" + state: directory + owner: root + group: root + mode: "0755" + when: matomo_archiving_enabled + +- name: "Deploy matomo-archive script" + ansible.builtin.template: + src: "matomo-archive.sh.j2" + dest: "{{ matomo_archive_script_path }}" + owner: root + group: root + mode: "0755" + when: matomo_archiving_enabled + +- name: "Deploy logrotate config" + ansible.builtin.template: + src: "logrotate-matomo-archive.j2" + dest: "/etc/logrotate.d/matomo-archive" + owner: root + group: root + mode: "0644" + when: + - matomo_archiving_enabled + - matomo_archive_logrotate_enabled + +- name: "Schedule cron job" + ansible.builtin.cron: + name: "Matomo CLI archiving (core:archive)" + user: root + minute: "{{ matomo_archive_cron_minute }}" + hour: "{{ matomo_archive_cron_hour }}" + day: "{{ matomo_archive_cron_day }}" + month: "{{ matomo_archive_cron_month }}" + weekday: "{{ matomo_archive_cron_weekday }}" + job: "{{ matomo_archive_script_path }}" + when: matomo_archiving_enabled diff --git a/roles/matomo_docker/tasks/main.yml b/roles/matomo_docker/tasks/main.yml index 2cedb33..35db11f 100644 --- a/roles/matomo_docker/tasks/main.yml +++ b/roles/matomo_docker/tasks/main.yml @@ -83,3 +83,8 @@ enabled: true state: started daemon_reload: true + + +- name: "Set up Matomo archiving" + ansible.builtin.import_tasks: archiving.yml + when: matomo_archiving_enabled diff --git a/roles/matomo_docker/templates/logrotate-matomo-archive.j2 b/roles/matomo_docker/templates/logrotate-matomo-archive.j2 new file mode 100644 index 0000000..9f048cd --- /dev/null +++ b/roles/matomo_docker/templates/logrotate-matomo-archive.j2 @@ -0,0 +1,9 @@ +{{ matomo_archive_log_file }} { + {{ matomo_archive_logrotate_frequency }} + rotate {{ matomo_archive_logrotate_rotate }} + missingok + notifempty + compress + delaycompress + copytruncate +} diff --git a/roles/matomo_docker/templates/matomo-archive.sh.j2 b/roles/matomo_docker/templates/matomo-archive.sh.j2 new file mode 100644 index 0000000..125d6ad --- /dev/null +++ b/roles/matomo_docker/templates/matomo-archive.sh.j2 @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +set -euo pipefail + +CONTAINER="{{ matomo_docker_container_name }}" +CONSOLE="{{ matomo_console_path }}" +LOG_FILE="{{ matomo_archive_log_file }}" +LOCK_FILE="{{ matomo_archive_lock_file }}" + +ts() { date -u +"%Y-%m-%dT%H:%M:%SZ"; } + +mkdir -p "$(dirname "$LOG_FILE")" + +# Prevent overlapping runs +exec 200>"$LOCK_FILE" +flock -n 200 || exit 0 + +echo "[$(ts)] starting core:archive" >> "$LOG_FILE" + +if docker exec -t "$CONTAINER" php "$CONSOLE" core:archive {{ matomo_archive_extra_args }} >> "$LOG_FILE" 2>&1; then + echo "[$(ts)] finished OK" >> "$LOG_FILE" +else + rc=$? + echo "[$(ts)] finished ERROR rc=$rc" >> "$LOG_FILE" + exit $rc +fi From df64ba995f8fa088686d60cdda27c79534a4a06c Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Tue, 17 Mar 2026 10:32:48 +0100 Subject: [PATCH 02/10] Remove logrotate configuration --- roles/matomo_docker/defaults/main.yml | 9 ++------- roles/matomo_docker/tasks/archiving.yml | 11 ----------- .../templates/logrotate-matomo-archive.j2 | 9 --------- 3 files changed, 2 insertions(+), 27 deletions(-) delete mode 100644 roles/matomo_docker/templates/logrotate-matomo-archive.j2 diff --git a/roles/matomo_docker/defaults/main.yml b/roles/matomo_docker/defaults/main.yml index 4f7f9b9..744ee98 100644 --- a/roles/matomo_docker/defaults/main.yml +++ b/roles/matomo_docker/defaults/main.yml @@ -58,10 +58,5 @@ matomo_archive_cron_day: "*" matomo_archive_cron_month: "*" matomo_archive_cron_weekday: "*" -# Extra args for `core:archive` (use "-vvv" temporarily for debugging) -matomo_archive_extra_args: "-q" - -# Logrotate policy -matomo_archive_logrotate_enabled: true -matomo_archive_logrotate_frequency: daily -matomo_archive_logrotate_rotate: 14 +# Extra args for `core:archive` +matomo_archive_extra_args: "-q" # quiet mode, no output unless error diff --git a/roles/matomo_docker/tasks/archiving.yml b/roles/matomo_docker/tasks/archiving.yml index bd6de2a..fb1a936 100644 --- a/roles/matomo_docker/tasks/archiving.yml +++ b/roles/matomo_docker/tasks/archiving.yml @@ -17,17 +17,6 @@ mode: "0755" when: matomo_archiving_enabled -- name: "Deploy logrotate config" - ansible.builtin.template: - src: "logrotate-matomo-archive.j2" - dest: "/etc/logrotate.d/matomo-archive" - owner: root - group: root - mode: "0644" - when: - - matomo_archiving_enabled - - matomo_archive_logrotate_enabled - - name: "Schedule cron job" ansible.builtin.cron: name: "Matomo CLI archiving (core:archive)" diff --git a/roles/matomo_docker/templates/logrotate-matomo-archive.j2 b/roles/matomo_docker/templates/logrotate-matomo-archive.j2 deleted file mode 100644 index 9f048cd..0000000 --- a/roles/matomo_docker/templates/logrotate-matomo-archive.j2 +++ /dev/null @@ -1,9 +0,0 @@ -{{ matomo_archive_log_file }} { - {{ matomo_archive_logrotate_frequency }} - rotate {{ matomo_archive_logrotate_rotate }} - missingok - notifempty - compress - delaycompress - copytruncate -} From 9379b6aadb391521fe35e5bb82108965788cb95e Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Tue, 17 Mar 2026 10:41:16 +0100 Subject: [PATCH 03/10] Fix lint and add Copyright info --- roles/matomo_docker/defaults/main.yml | 2 +- roles/matomo_docker/tasks/archiving.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/matomo_docker/defaults/main.yml b/roles/matomo_docker/defaults/main.yml index 744ee98..afd08a2 100644 --- a/roles/matomo_docker/defaults/main.yml +++ b/roles/matomo_docker/defaults/main.yml @@ -58,5 +58,5 @@ matomo_archive_cron_day: "*" matomo_archive_cron_month: "*" matomo_archive_cron_weekday: "*" -# Extra args for `core:archive` +# Extra args for `core:archive` matomo_archive_extra_args: "-q" # quiet mode, no output unless error diff --git a/roles/matomo_docker/tasks/archiving.yml b/roles/matomo_docker/tasks/archiving.yml index fb1a936..6eddfbc 100644 --- a/roles/matomo_docker/tasks/archiving.yml +++ b/roles/matomo_docker/tasks/archiving.yml @@ -1,4 +1,6 @@ --- +# copyright Utrecht University + - name: "Ensure log directory exists" ansible.builtin.file: path: "{{ matomo_archive_log_dir }}" From 8d78b77396b444465722ad79f7fe65d9f627b197 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Tue, 17 Mar 2026 13:22:42 +0100 Subject: [PATCH 04/10] removed the container name parameter and reformated comments --- roles/matomo_docker/defaults/main.yml | 15 +++------------ roles/matomo_docker/tasks/archiving.yml | 2 +- .../matomo_docker/templates/matomo-archive.sh.j2 | 2 +- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/roles/matomo_docker/defaults/main.yml b/roles/matomo_docker/defaults/main.yml index afd08a2..66bb0d5 100644 --- a/roles/matomo_docker/defaults/main.yml +++ b/roles/matomo_docker/defaults/main.yml @@ -35,18 +35,12 @@ matomo_cert_mode: selfsigned matomo_static_cert: notset matomo_static_cert_key: notset -# Matomo CLI pre-archiving -# Enable scheduled CLI archiving +# Matomo archiving configuration matomo_archiving_enabled: true - -# Docker container name running Matomo -matomo_docker_container_name: matomo - -# Matomo console path inside the container matomo_console_path: /var/www/html/matomo/console +matomo_archive_extra_args: "-q" # quiet mode, no output unless error -# Host paths for script/log/lock -matomo_archive_script_path: /usr/local/bin/matomo-archive +matomo_archive_script_path: /usr/local/bin/matomo-archive.sh matomo_archive_log_dir: /var/log/matomo matomo_archive_log_file: "{{ matomo_archive_log_dir }}/archive.log" matomo_archive_lock_file: /run/matomo-archive.lock @@ -57,6 +51,3 @@ matomo_archive_cron_hour: "*" matomo_archive_cron_day: "*" matomo_archive_cron_month: "*" matomo_archive_cron_weekday: "*" - -# Extra args for `core:archive` -matomo_archive_extra_args: "-q" # quiet mode, no output unless error diff --git a/roles/matomo_docker/tasks/archiving.yml b/roles/matomo_docker/tasks/archiving.yml index 6eddfbc..d635ae1 100644 --- a/roles/matomo_docker/tasks/archiving.yml +++ b/roles/matomo_docker/tasks/archiving.yml @@ -21,7 +21,7 @@ - name: "Schedule cron job" ansible.builtin.cron: - name: "Matomo CLI archiving (core:archive)" + name: "Matomo archiving with core:archive" user: root minute: "{{ matomo_archive_cron_minute }}" hour: "{{ matomo_archive_cron_hour }}" diff --git a/roles/matomo_docker/templates/matomo-archive.sh.j2 b/roles/matomo_docker/templates/matomo-archive.sh.j2 index 125d6ad..86d3964 100644 --- a/roles/matomo_docker/templates/matomo-archive.sh.j2 +++ b/roles/matomo_docker/templates/matomo-archive.sh.j2 @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -CONTAINER="{{ matomo_docker_container_name }}" +CONTAINER="matomo" # name of the Matomo container CONSOLE="{{ matomo_console_path }}" LOG_FILE="{{ matomo_archive_log_file }}" LOCK_FILE="{{ matomo_archive_lock_file }}" From 4d9665756aa5d3350c5cd302489519b6b80bec4d Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Wed, 18 Mar 2026 14:22:25 +0100 Subject: [PATCH 05/10] disable browser archiving and replace cronrunner to www-data --- docker/images/matomo/matomo-init.sh | 1 + roles/matomo_docker/defaults/main.yml | 9 +++++---- roles/matomo_docker/templates/matomo-archive.sh.j2 | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docker/images/matomo/matomo-init.sh b/docker/images/matomo/matomo-init.sh index d3be856..8a654b6 100644 --- a/docker/images/matomo/matomo-init.sh +++ b/docker/images/matomo/matomo-init.sh @@ -61,6 +61,7 @@ then before_update "Setting up Apache vhost" --first-user="$MATOMO_FIRST_USER_NAME" \ --first-user-email="$MATOMO_FIRST_USER_EMAIL" \ --first-user-pass="$MATOMO_FIRST_USER_PASSWORD" + crudini --set /var/www/html/matomo/config/config.ini.php General browser_archiving_disabled_enforce 1 crudini --set /var/www/html/matomo/config/config.ini.php General force_ssl 1 crudini --set /var/www/html/matomo/config/config.ini.php General assume_secure_protocol 1 crudini --set /var/www/html/matomo/config/config.ini.php General proxy_client_headers[] HTTP_X_FORWARDED_FOR diff --git a/roles/matomo_docker/defaults/main.yml b/roles/matomo_docker/defaults/main.yml index 66bb0d5..f6fbff3 100644 --- a/roles/matomo_docker/defaults/main.yml +++ b/roles/matomo_docker/defaults/main.yml @@ -35,18 +35,19 @@ matomo_cert_mode: selfsigned matomo_static_cert: notset matomo_static_cert_key: notset -# Matomo archiving configuration +# Archiving configuration matomo_archiving_enabled: true +matomo_container_name: matomo +matomo_container_user: www-data matomo_console_path: /var/www/html/matomo/console -matomo_archive_extra_args: "-q" # quiet mode, no output unless error matomo_archive_script_path: /usr/local/bin/matomo-archive.sh matomo_archive_log_dir: /var/log/matomo matomo_archive_log_file: "{{ matomo_archive_log_dir }}/archive.log" matomo_archive_lock_file: /run/matomo-archive.lock -# Cron schedule (default: hourly at minute 15) -matomo_archive_cron_minute: "15" +# Archiving cron schedule (default: hourly at minute 5) +matomo_archive_cron_minute: "5" matomo_archive_cron_hour: "*" matomo_archive_cron_day: "*" matomo_archive_cron_month: "*" diff --git a/roles/matomo_docker/templates/matomo-archive.sh.j2 b/roles/matomo_docker/templates/matomo-archive.sh.j2 index 86d3964..e3e257b 100644 --- a/roles/matomo_docker/templates/matomo-archive.sh.j2 +++ b/roles/matomo_docker/templates/matomo-archive.sh.j2 @@ -1,7 +1,8 @@ #!/usr/bin/env bash set -euo pipefail -CONTAINER="matomo" # name of the Matomo container +CONTAINER="{{ matomo_container_name }}" +CRON_USER="{{ matomo_container_user }}" CONSOLE="{{ matomo_console_path }}" LOG_FILE="{{ matomo_archive_log_file }}" LOCK_FILE="{{ matomo_archive_lock_file }}" @@ -16,7 +17,7 @@ flock -n 200 || exit 0 echo "[$(ts)] starting core:archive" >> "$LOG_FILE" -if docker exec -t "$CONTAINER" php "$CONSOLE" core:archive {{ matomo_archive_extra_args }} >> "$LOG_FILE" 2>&1; then +if docker exec -u "$CRON_USER" "$CONTAINER" php "$CONSOLE" core:archive >> "$LOG_FILE" 2>&1; then echo "[$(ts)] finished OK" >> "$LOG_FILE" else rc=$? From 5acbc8879283e78a73317a3921a0c6a3234a0d8e Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Thu, 19 Mar 2026 11:34:38 +0100 Subject: [PATCH 06/10] fix missing dollar sign for db-pass --- docker/images/matomo/matomo-init.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/images/matomo/matomo-init.sh b/docker/images/matomo/matomo-init.sh index 8a654b6..449e0e7 100644 --- a/docker/images/matomo/matomo-init.sh +++ b/docker/images/matomo/matomo-init.sh @@ -52,7 +52,7 @@ then before_update "Setting up Apache vhost" cd /var/www/html/matomo ./console matomo:install --no-interaction \ --db-username="$MATOMO_DATABASE_USERNAME" \ - --db-pass="MATOMO_DATABASE_PASSWORD" \ + --db-pass="$MATOMO_DATABASE_PASSWORD" \ --db-host="$MATOMO_DATABASE_HOST" \ --db-port=3306 \ --db-name="$MATOMO_DATABASE_DBNAME" \ From 1f1ea5e5ce85862e7300d177417240adc47e98f0 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Thu, 26 Mar 2026 16:12:35 +0100 Subject: [PATCH 07/10] Replace when condition with state for cron tasks --- roles/matomo_docker/tasks/archiving.yml | 12 +++++++++--- roles/matomo_docker/tasks/main.yml | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/roles/matomo_docker/tasks/archiving.yml b/roles/matomo_docker/tasks/archiving.yml index d635ae1..25049d1 100644 --- a/roles/matomo_docker/tasks/archiving.yml +++ b/roles/matomo_docker/tasks/archiving.yml @@ -10,7 +10,7 @@ mode: "0755" when: matomo_archiving_enabled -- name: "Deploy matomo-archive script" +- name: "Deploy matomo-archive script (when enabled)" ansible.builtin.template: src: "matomo-archive.sh.j2" dest: "{{ matomo_archive_script_path }}" @@ -19,7 +19,13 @@ mode: "0755" when: matomo_archiving_enabled -- name: "Schedule cron job" +- name: Remove matomo-archive script (when disabled) + ansible.builtin.file: + path: "{{ matomo_archive_script_path }}" + state: absent + when: not matomo_archiving_enabled + +- name: Schedule archiving cron job ansible.builtin.cron: name: "Matomo archiving with core:archive" user: root @@ -29,4 +35,4 @@ month: "{{ matomo_archive_cron_month }}" weekday: "{{ matomo_archive_cron_weekday }}" job: "{{ matomo_archive_script_path }}" - when: matomo_archiving_enabled + state: "{{ 'present' if matomo_archiving_enabled else 'absent' }}" diff --git a/roles/matomo_docker/tasks/main.yml b/roles/matomo_docker/tasks/main.yml index 35db11f..43ebe1a 100644 --- a/roles/matomo_docker/tasks/main.yml +++ b/roles/matomo_docker/tasks/main.yml @@ -87,4 +87,3 @@ - name: "Set up Matomo archiving" ansible.builtin.import_tasks: archiving.yml - when: matomo_archiving_enabled From 21cdd780e4826e1fae2bf3bc52d290216878b785 Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Thu, 26 Mar 2026 16:48:11 +0100 Subject: [PATCH 08/10] Replace root user with matomo user --- roles/matomo_docker/defaults/main.yml | 6 +++--- roles/matomo_docker/tasks/archiving.yml | 19 ++++++++++++++----- .../templates/matomo-archive.sh.j2 | 6 +++--- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/roles/matomo_docker/defaults/main.yml b/roles/matomo_docker/defaults/main.yml index f6fbff3..920f3e9 100644 --- a/roles/matomo_docker/defaults/main.yml +++ b/roles/matomo_docker/defaults/main.yml @@ -41,10 +41,10 @@ matomo_container_name: matomo matomo_container_user: www-data matomo_console_path: /var/www/html/matomo/console -matomo_archive_script_path: /usr/local/bin/matomo-archive.sh -matomo_archive_log_dir: /var/log/matomo +matomo_archive_script_path: /home/{{ matomo_user }}/matomo-archive/matomo-archive.sh +matomo_archive_log_dir: "/home/{{ matomo_user }}/log" matomo_archive_log_file: "{{ matomo_archive_log_dir }}/archive.log" -matomo_archive_lock_file: /run/matomo-archive.lock +matomo_archive_lock_file: "/home/{{ matomo_user }}/matomo-archive/archive.lock" # Archiving cron schedule (default: hourly at minute 5) matomo_archive_cron_minute: "5" diff --git a/roles/matomo_docker/tasks/archiving.yml b/roles/matomo_docker/tasks/archiving.yml index 25049d1..1ec2b04 100644 --- a/roles/matomo_docker/tasks/archiving.yml +++ b/roles/matomo_docker/tasks/archiving.yml @@ -5,17 +5,26 @@ ansible.builtin.file: path: "{{ matomo_archive_log_dir }}" state: directory - owner: root - group: root + owner: "{{ matomo_user }}" + group: "{{ matomo_user }}" mode: "0755" when: matomo_archiving_enabled +- name: Ensure matomo-archive directory exists + ansible.builtin.file: + path: "{{ matomo_archive_script_path | dirname }}" + state: directory + owner: "{{ matomo_user }}" + group: "{{ matomo_user }}" + mode: "0755" + when: matomo_archiving_enabled + - name: "Deploy matomo-archive script (when enabled)" ansible.builtin.template: src: "matomo-archive.sh.j2" dest: "{{ matomo_archive_script_path }}" - owner: root - group: root + owner: "{{ matomo_user }}" + group: "{{ matomo_user }}" mode: "0755" when: matomo_archiving_enabled @@ -28,7 +37,7 @@ - name: Schedule archiving cron job ansible.builtin.cron: name: "Matomo archiving with core:archive" - user: root + user: "{{ matomo_user }}" minute: "{{ matomo_archive_cron_minute }}" hour: "{{ matomo_archive_cron_hour }}" day: "{{ matomo_archive_cron_day }}" diff --git a/roles/matomo_docker/templates/matomo-archive.sh.j2 b/roles/matomo_docker/templates/matomo-archive.sh.j2 index e3e257b..9f8800e 100644 --- a/roles/matomo_docker/templates/matomo-archive.sh.j2 +++ b/roles/matomo_docker/templates/matomo-archive.sh.j2 @@ -9,15 +9,15 @@ LOCK_FILE="{{ matomo_archive_lock_file }}" ts() { date -u +"%Y-%m-%dT%H:%M:%SZ"; } -mkdir -p "$(dirname "$LOG_FILE")" +mkdir -p "$(dirname "$LOG_FILE")" "$(dirname "$LOCK_FILE")" # Prevent overlapping runs exec 200>"$LOCK_FILE" -flock -n 200 || exit 0 +/bin/flock -n 200 || exit 0 echo "[$(ts)] starting core:archive" >> "$LOG_FILE" -if docker exec -u "$CRON_USER" "$CONTAINER" php "$CONSOLE" core:archive >> "$LOG_FILE" 2>&1; then +if /bin/docker exec -u "$CRON_USER" "$CONTAINER" php "$CONSOLE" core:archive >> "$LOG_FILE" 2>&1; then echo "[$(ts)] finished OK" >> "$LOG_FILE" else rc=$? From 573f22f32ee2d1bda5eb13ff2a86dd281034933f Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Thu, 26 Mar 2026 16:51:55 +0100 Subject: [PATCH 09/10] Add a warning when lock is held --- roles/matomo_docker/templates/matomo-archive.sh.j2 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/roles/matomo_docker/templates/matomo-archive.sh.j2 b/roles/matomo_docker/templates/matomo-archive.sh.j2 index 9f8800e..44f374f 100644 --- a/roles/matomo_docker/templates/matomo-archive.sh.j2 +++ b/roles/matomo_docker/templates/matomo-archive.sh.j2 @@ -13,7 +13,11 @@ mkdir -p "$(dirname "$LOG_FILE")" "$(dirname "$LOCK_FILE")" # Prevent overlapping runs exec 200>"$LOCK_FILE" -/bin/flock -n 200 || exit 0 + +if ! /bin/flock -n 200; then + echo "[$(ts)] WARNING: archive lock is held" >> "$LOG_FILE" + exit 0 +fi echo "[$(ts)] starting core:archive" >> "$LOG_FILE" From 7a480629e293bb83ffd264735d1a29a8d2326bfa Mon Sep 17 00:00:00 2001 From: FuHsinyu Date: Thu, 26 Mar 2026 16:54:20 +0100 Subject: [PATCH 10/10] Trailing spaces --- roles/matomo_docker/tasks/archiving.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roles/matomo_docker/tasks/archiving.yml b/roles/matomo_docker/tasks/archiving.yml index 1ec2b04..d6fb653 100644 --- a/roles/matomo_docker/tasks/archiving.yml +++ b/roles/matomo_docker/tasks/archiving.yml @@ -18,7 +18,7 @@ group: "{{ matomo_user }}" mode: "0755" when: matomo_archiving_enabled - + - name: "Deploy matomo-archive script (when enabled)" ansible.builtin.template: src: "matomo-archive.sh.j2" @@ -33,7 +33,7 @@ path: "{{ matomo_archive_script_path }}" state: absent when: not matomo_archiving_enabled - + - name: Schedule archiving cron job ansible.builtin.cron: name: "Matomo archiving with core:archive"