4

I recently had an episode where I put a site into maintenance mode to perform a security upgrade and forgot to go live again afterwards, resulting in almost a day of downtime before I caught the error.

I thought I could set up a rule to send me an e-mail whenever cron runs if it detects that the site is in maintenance mode, but I don't think that's going to work because cron can't execute when maintenance mode is on. A preliminary test seems to confirm that. I put the site in maintenance mode, attempted to run cron manually, and no e-mail was generated.

Is there another module or method I could use to send myself a reminder so this won't happen again?

1
  • I confess forgetting to go live but it also has happened that I have switched the site on, only to find out after a day that it is in maintenance. Plus people are reporting cases where the site goes on maintenance on its own. So, good question. Commented Sep 23, 2015 at 22:17

2 Answers 2

1

I, personally, can think of a hamfisted, hacky way do do this, but I would prefer for someone else to provide a more elegant solution.

My web host doesn't allow SSH, but does have a "tasks" feature that essentially pulls a designated website URL at regular intervals; I'm currently using it to run Cron externally and get around Drupal 7's default Poormanscron implementation.

So I could bootstrap Drupal from a custom script and have it get pulled as an hourly task. It would variable_get('site_offline') and do nothing (or maybe redirect to index.php in case a 'bot discovers it) if false and invoke the Rule that sends the reminder e-mail if true.

Heck, if Rules or Drupal's e-mail abilities are also disabled while in maintenance mode, I can just generate the e-mail with straight PHP.

0

A possible solution to answer this question is to create a custom rule (using Rules) that looks like so:

  • Rules Event: Drupal is initializing.
  • Rules Condition: check if the site is in maintenance mode, using the Rules Condition Site Variable module (see below for more details).
  • Rules Action: Send an appropriate eMail.

More details about the above Rules Condition:

  • The Rules Condition Site Variable module allows a rule to have a Rules Condition that explicitly references a variable by name. That way the Rules Condition does NOT (repeat: NOT) have to rely on inline PHP code to check the value of site variable site_offline (= the equivalent of variable_get('site_offline')).
  • How to use this module (quotes from its project page):

    • In your rule, create a new condition, and select 'Site variable to check'.
    • Set the 'The site variable you want to check' field to be the name of the variable you wish to check against. You do not need to surround the variable name with quotes.
    • Set the 'The value that the site variable should have' field to be the value that the variable should be in order for the condition to return true.

Obviously, because of the nature of the Rules Event used here, it does NOT depend on the execution of a cron job.

A possible refinement is to enable this rule when putting a site in maintenance mode, and disable the rule again when maintenance mode is finished.

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.