Reduce the risk of "modulitis"
As an alternative to the Scheduled Maintenance module, suggested in the previous answer, you can also use the Rules module for this. Instead of installing yet another module that you can only use for "announcing scheduled maintenance".
If you don't have Rules enabled yet, you can probably (actually: pretty sure) use it to implement lots of other features in your site. That will help to reduce the risk of your site suffering "modulitis", aka "way too much contributed modules that slow down a site").
Creating a custom Rule
Have a look at this custom rule (in Rules export format):
{ "rules_announce_scheduled_maintenance" : {
"LABEL" : "Announce scheduled maintenance",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules" ],
"ON" : { "init" : [] },
"IF" : [
{ "data_is" : {
"data" : [ "site:current-date" ],
"op" : "\u003E",
"value" : 1477639800
}
},
{ "data_is" : {
"data" : [ "site:current-date" ],
"op" : "\u003C",
"value" : 1477726200
}
},
{ "user_has_role" : {
"account" : [ "site:current-user" ],
"roles" : { "value" : { "2" : "2" } }
}
}
],
"DO" : [
{ "drupal_message" : {
"message" : "\u003Cstrong\u003EMaintenance upcoming!\u003C\/strong\u003E Please note that access to this site will be limited due to scheduled site maintenance.",
"type" : "warning"
}
}
]
}
}
If you have the Rules UI enabled, you can import the above rule in your own site. Some details about what this rule actually does:
- The rule is triggered (= Rules Event) for anything a user/visitor does in the site (because of Rules Event Drupal is initializing being used).
- The first 2 Rules Conditions check is the site's current time (in GMT) is between
2016-10-28 07:30:00
and 2016-10-29 07:30:00
.
- The 3rd Rules Condition verifies if the user is authenticated, so nothing happens for anonymous users. Remove or adapt this Rules Condition to fit your needs.
If all Rules Conditions are satisfied, then the Rules Action will display a message (of type warning) with content like so:
Maintenance upcoming! Please note that access to this site will be limited due to scheduled site maintenance.
If you want, change the type of message from Warning to Status (= Information only), or to change the actual message content, which BTW can also include some HTML markup.
How to use this rule
- Any time you have a maintenance window coming up, you only adapt the "from" and "to" dates in the Rules Conditions.
- You can either leave this rule enabled permanently, or you disable the rule and only enable it around the timeframe you want to show this maintenance message.
- After the "to" date/time has arrived, no more message will be shown. Even if you don't (or forget to) disable this rule.
Possible improvements
You have all the power of Rules available to further improve this rule, e.g.:
- Only trigger this rule when (e.g.) "Content is viewed" (by replacing the Rules Event with any other event that fits).
- Only show it on selected pages (like the frontpage?).
- Send an eMail to an admin if special conditions are met.
- Refine the message being shown (e.g. with an hyperlink to a page with more details about scheduled maintenance).