Check (and stop) for running auto-archive before upgrading the database

Good day everyone!

So I have a Matomo installation on Linux and it has a crontab like the following:

$ crontab -u www-data -l
MAILTO="sysadmin@domain.com"
# Matomo report archiver
5 * * * * /usr/bin/php /var/www/matomo/console core:archive --url=https://matomo.domain.com/ | /usr/bin/logger -t matomo

I am in the process of writing an Ansible Playbook to install and upgrade Matomo. While doing the upgrade bit I created a task to upgrade the database, using the following command:

php console --no-ansi --no-interaction --yes core:update

And I was wondering what would happen if the auto-archiver was running while the database upgrade task was executed. Moreover, is there a way to safely detect and stop a currently-running auto-archiving process?

I don’t mean disabling cron (I know I have to do that at the beginning), but in case it had just started, right before going for the upgrade.

Thanks in advance.

1 Like

You can achieve this by entering Maintenace mode. Once in this mode any archive attempt will get the following.

matomo.mysite.com Archiving won't run because maintenance mode is enabled

How do I momentarily disable Matomo User Interface and/or Matomo visitor Tracking? FAQ - How to - Matomo Analytics Platform

Hi, @Jason_1282, and thanks for your reply.

I am already doing that at the begining of my Ansible playbook. My question was about what happens when an archiving job is already running, i.e., had started prior to the task in the palybook that upgrades the database schema:

php console --no-ansi --no-interaction --yes core:update

Will the running command block the database upgrade and keep the installation in maintenance mode for around 30 minutes (durrent duration of my archiving cron job)? Will the archiving job quickly detect the new maintenance mode and stop processing sites?

Thanks in advance.

You would probably be better to see if the archive is running by checking the process list for core:archive. I am not sure what would happen if or even if you could go into Maintenace mode during an archive. If you could and the archive is killed it will start over as it can only mark it done when it’s done.

Yes, I think I might just do that. For reference, I could not find a way to filter by core:archive using killall, so this is the closest I got:

killall --signal SIGTERM --user www-data --interactive --wait /usr/bin/php

The --interactive bit would go away in production.

Using pkill, the command would be something like this:

pkill -SIGTERM --full --uid $(id --user www-data) core:archive

Thanks for your help.