I have a D9/Civi site and the main Civi cron is set up to run every 5 minutes using cv :

/usr/local/bin/cv api job.execute --user=xxx --cwd=/home/xx/sites/default/web --quiet

The cron job runs, but I get an email every time which reports:

In Drupal.php line 179:

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

How can I stop this from happening? Is it do with the permissions of the selected user?

  • When you say "the cron job runs" are you saying that some or all of the corresponding civicrm system jobs run? If that's the case, then it's likely just one of your system jobs that is generating that message and failing.
    – Alan Dixon
    Aug 22, 2023 at 19:43
  • 1
    What happens when you run the cron job manually (as whatever user your cron is running as, without the --quiet)?
    – Alan Dixon
    Aug 22, 2023 at 19:44
  • If I run the job manually from the command line using cv and without the --quiet, I get back: { "is_error": 0, "version": 3, "count": 1, "values": 1 }
    – Graham
    Aug 24, 2023 at 16:40
  • So, if I remove the --quiet parameter from the crontab I get an email with the above information. Adding it back in and I get an email with the note about $container not bneing initialized.
    – Graham
    Aug 25, 2023 at 6:13
  • So as a workaround I've edited the crontab line to remove the --quiet command and added > dev/null 2>&1 to end of the line, which as I understand dumps all output. the downside of this approach is that I won't be made aware if/when it breaks for some reason. Why is --quiet triggering an email?
    – Graham
    Aug 25, 2023 at 8:23

3 Answers 3


I have one Drupal 9 site with this problem, and several more that don't. I don't know the root cause of the issue, but I know that adding --level=cms-full to the cv command fixes the issue.


So, if your civicrm system jobs are all running, then the question is about where the extra Drupal error email is coming from (regardless of whether it gets emailed to you or just displayed on the command line when you don't use --quiet).

The success of the manual run suggests one of your system jobs is generating that message but not quitting in any fatal way.

I'd recommend that you look through your individual system jobs that run with each cron and run them individually via the web interface and see if they give you any clues.

If that doesn't help, or if you're happy enough on the command line, you can just run them each via the command line (the civicrm system cron is just a way of selecting and running individual system jobs).

I'd guess it's coming from an older extension that doesn't play well with modern Drupal, or a Drupal module that's implementing a civicrm system job.


Two thoughts:

  • Check the version of cv.
  • I don't use the cwd option so maybe it does something different for boot ordering, and I notice sites/default/web is an odd path but you might just have typed that as an example. If that is the right path and it's maybe the use of cwd, then an alternate is change your task to be cd /home/xx/whatever; /usr/local/bin/cv api3 ...etc...
  • Thanks. cv version reports as v0.3.46
    – Graham
    Aug 22, 2023 at 9:18
  • As I understand it cwd is simply used to specify the root directory (where Drupal's index.php file sits) of the site where I want the api call to be made. Maybe I should be more specific and set cwd to the path to civicrm, or cron.php?
    – Graham
    Aug 22, 2023 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.