1

Running cron with crontab is not working on our Drupal 8 website if the user is anonymous. If I'm logged in as admin, I can run cron with the button or the url with key. If I'm not logged in, cron doesn't run with url with key.

Running from crontab is of course anonymous and so cron is not running.

Any ideas?

Version: Drupal 8 beta 4

Line in crontab:

*/5 * * * * wget -O - -q -t 1 http://www.entityone.be/nl/cron/theactualcronkeyhere
  • anything in the drupal log messages ? – rtome Feb 23 '15 at 12:37
  • No, nothing in the logs. Not even an access denied. – Maarten De Block Feb 23 '15 at 12:50
  • Are you invoking cron via cURL, wget, Drush? Did you check /var/log/daemon.log and does it report anything related to your cron job here? Did you read drupal.org/node/23714 and did it help? – anavarre Feb 23 '15 at 18:32
  • @anavarre I added the line in crontab to the question. I'm using wget. I did read drupal.org/node/23714, but nothing helpful for this issue. I don't have access to /var/log/daemon.log, only to the apache logs. It may be worth mentioning another cron for Drupal 7 is running on the same server successfully. – Maarten De Block Feb 23 '15 at 19:03
  • Do you see anything in the apache access log? What happens if you explicitly provide a wrong cron key? No reason that shouldn't work – Berdir Feb 23 '15 at 19:54
1

I know the question is old, but I faced a similar problem and would like to help people coming from google.

I assume you have a function in one of your specific cron hooks which needs extra permissions to run which won't work because Drupal runs cron as an anonymous user.

What helps is to identify which hook_cron needs elevated rights and switch to e.g. the admin account before the affected code runs:

use Drupal\Core\Session\UserSession;

// call the account switcher service
$accountSwitcher = \Drupal::service('account_switcher');
// switch to the admin user
$accountSwitcher->switchTo(new UserSession(['uid' => 1]));

// run your code here

// switch back to old session
$accountSwitcher->switchBack();
0

I use following line and it works pretty well on drupal 8.0.5

wget -q http://domain/cron/theactualcronkeyhere -O /dev/null

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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