Skip to content

fix: export Mautic DB vars to cron jobs (backport to mautic7) - #16

Merged
henmohr merged 2 commits into
mautic7from
backport/cron-env-mautic7
Sep 10, 2026
Merged

fix: export Mautic DB vars to cron jobs (backport to mautic7)#16
henmohr merged 2 commits into
mautic7from
backport/cron-env-mautic7

Conversation

@henmohr

@henmohr henmohr commented Sep 10, 2026

Copy link
Copy Markdown

Problem

The mautic_cron container schedules Mautic's console commands, but the cron daemon does not inherit the container environment. entrypoint_mautic_cron.sh only exported the PHP_INI_VALUE_* variables to /tmp/cron.env (used as BASH_ENV), so config/local.php could not resolve the database connection through getenv('MAUTIC_DB_*').

As a result every scheduled command failed with:

SQLSTATE[HY000] [2002] No such file or directory

because db_host was empty and PDO fell back to the local unix socket. Segments were never rebuilt and campaigns were never triggered.

Fix

Backport of e71d349 (main) to the mautic7 release branch: export MAUTIC_DB_* / MAUTIC_SITE_URL to /tmp/cron.env and define MAUTIC_DB_DATABASE from MAUTIC_DB_NAME when it is not set.

Validation

The same change was applied to a Mautic 7.2 deployment (ghcr.io/librecodecoop/mautic:7.2-apache, entrypoint bind-mounted). Before the change every run failed; afterwards:

  • mautic:segments:update - OK
  • mautic:campaigns:rebuild - OK
  • mautic:campaigns:trigger - OK

with zero SQLSTATE errors in the container logs.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-10T18:57:16.570396Z c260dfa PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

(cherry picked from commit e71d349)
Signed-off-by: henmohr <henriquemohr@redes.ufsm.br>
The line is written verbatim into /tmp/cron.env and evaluated later by the
cron job, so the variables must not be expanded at generation time.
ShellCheck flags the single-quoted string as SC2016. Suppress it explicitly,
as already done for the mautic install check below.

Signed-off-by: henmohr <henriquemohr@redes.ufsm.br>
@henmohr
henmohr force-pushed the backport/cron-env-mautic7 branch from 8dccf93 to e51dee8 Compare September 10, 2026 19:03
@henmohr
henmohr merged commit 3da2636 into mautic7 Sep 10, 2026
4 checks passed
@henmohr
henmohr deleted the backport/cron-env-mautic7 branch September 10, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant