0

I am trying to execute drush commands through a crontab for a Drupal 8 site. These commands work when I call them directly, but when run through my user's crontab I get the following error:

\Drupal::$container is not initialized yet. \Drupal::setContainer() must be
called with a real container.

Other posts suggest this is a bug within older versions of Drush, but I am on 10.3.5.

I have tried a number of things over the past few hours including reconfiguring cron, but ultimately it seems Drush is not bootstrapping Drupal correctly, but I need to be able to run the queue from cron

This is a test command I'm running which just adds to the Drupal log...

crontab (my user)

* * * * * /var/www/html/vendor/bin/drush scr /var/www/html/scripts/what.php -r /var/www/html/web

what.php

<?php
\Drupal::logger('mymod')->info("CHECKING IN FROM CRON CLI...");

Here is another command, closer to what I'm trying to accomplish... crontab (my user)

* * * * * /var/www/html/vendor/bin/drush queue:run commerce_recurring -r /var/www/html/web >> /var/www/html/private/logs/cron_commerce_recurring.log

The error I get here is:

Command queue:run was not found. Drush was unable to query the database. As
a result, many commands are unavailable. Re-run your command with --debug
to see relevant log messages.

I get this same error when running this command with drupal console.

Any suggestions appreciated.

Thanks.

bfuzze
  • 438
  • 8
  • 15

1 Answers1

0

This turned out to be a database connectivity issue. The tricky part was getting to the error. I had to install an MTA, so that cron could write errors to my local user's mailbox and then add the --debug option, so that I could see the real error.

I'm working on a DDEV instance and for some reason the DDEV settings were not being loaded. An issue for another day...

bfuzze
  • 438
  • 8
  • 15