0

I have an issue with a website running Drupal 8. I cannot seem to get cron working. If I go to the status page and click 'run now' it works. If I try to open the cron settings (/admin/config/system/cron) I get an error. The log reports the following:

Symfony\Component\Routing\Exception\InvalidParameterException: Parameter "key" for route "system.cron" must match "[^/]++" ("" given) to generate a corresponding URL. in Drupal\Core\Routing\UrlGenerator->doGenerate() (line 202 of /var/www/exin.com/files/core/lib/Drupal/Core/Routing/UrlGenerator.php).

I looked up the system.cron path in the core files and found it attached to /cron/{key}, so that is not the settings page. It is the URL I was supposed to use for the cron tasks. Calling that URL (replacing {key} with my token) generates a permission denied error, even if I open it when logged in as administrator.

I found the key on the status page by looking at the URL of the 'run now' button (/admin/reports/status/run-cron?token=mytoken). Is this the correct token?

I'm running Drupal 8.3.7, which was updated from version 8.3.1, where I had the same issue.

I'm also using the Domain access module and some creative nginx configuration to open different "domains" through a proxy, which (for example) takes users from www.mysite.com/fr/ to fr.mysite.com. This was necessary since the Domain access module could not work with subdirectories. It caused a lot of issues which we managed to resolve, but this one sticks. So I'm not sure it is caused by either this module or the nginx configuration, but I feel it is important information.

2

The error is coming obviously from these lines of code in the cron settings form, when it tries to build the cron link:

$cron_url = $this->url('system.cron', ['key' => $this->state->get('system.cron_key')], ['absolute' => TRUE]);
$form['cron_url'] = [
  '#markup' => '<p>' . t('To run cron from outside the site, go to <a href=":cron">@cron</a>', [':cron' => $cron_url, '@cron' => $cron_url]) . '</p>',
];

So you somehow lost the State variable system.cron_key, which is on your site "" and causes the error. You find this in the database in the table key_value and collection state.

To set a new key you can rerun this code from system_install():

  // Populate the cron key state variable.
  $cron_key = \Drupal\Component\Utility\Crypt::randomBytesBase64(55);
  \Drupal::state()->set('system.cron_key', $cron_key);
  • Thank you, this was indeed the issue. Somehow a serialized object was stored in that field. – Frank Sep 6 '17 at 7:13

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.