My CRON setup considerations in a container

Hi

Here are my CRON setup considerations in a container should anyone end up with the same need.

Summary: on host run cronjob that starts a job inside the container that uses wget to fetch the correct url from localhost.

I’m running docker.io/upshift/dolibarr and in front of that is an nginx consider that handles HTTPS + the other stuff I also run on this machine.

Home → Setup → Modules/Applications
search for schedule and select “SCHEDULED JOBS”

Under the Miscellaneous tab I basically have 2 activation methods.

I can either use an url or I can execute a script.

But the docker.io/upshift/dolibarr image does not come with cron. So my options are either to install it, or run CRON somewhere else. I just choose to run it at my host because that has CRON installed, but first I need to get the script to work.

Okay, so I just run it

podman exec -it dolibarr /usr/src/dolibarr/scripts/cron/cron_run_jobs.php ***REDACTED**** someusername 
env: can't execute 'php': No such file or directory

okay, so insert /usr/bin/php in front?

podman exec -it dolibarr /usr/bin/php /usr/src/dolibarr/scripts/cron/cron_run_jobs.php ***REDACTED**** someusername
Error: executable file `/usr/bin/php` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found

Aha, so ls and figure out that it’s called /usr/bin/php - which might change in a new version as PHP is upgraded.

But that doesn’t work anyway

podman exec -it dolibarr /usr/bin/php82 /usr/src/dolibarr/scripts/cron/cron_run_jobs.php ***REDACTED**** someusername
PHP Fatal error:  Uncaught Error: Failed opening required '/usr/src/dolibarr/scripts/cron/../../htdocs/master.inc.php' (include_path='.:/usr/share/php82') in /usr/src/dolibarr/scripts/cron/cron_run_jobs.php:62
Stack trace:
#0 {main}
  thrown in /usr/src/dolibarr/scripts/cron/cron_run_jobs.php on line 62

So I decided to look at the url method which worked fine in my laptop browser, but still starting it inside the container.

podman exec dolibarr wget -qO - 'http://localhost/dolibarr/public/cron/cron_run_jobs_by_url.php?securitykey=***REDACTED****&userlogin=someusername' 1> /dev/null

the -q makes wget quiet
the -O - makes wget write to stdout, you could also write -O /dev/stdout

The final 1> /dev/null makes the command silent unless there are errors, and thus I won’t get any emails from CRON job execution unless there is an error.