Score:-1

Not allowing the user to access the website within the given time period

ro flag

My client want to offline the site for 12:00 AM to 06:00 AM and show this message to users. How can I achieve this in drupal8

ro flag
This website is created in drupal8.x
Kevin avatar
in flag
Im sure there are several modules for this. Maintenance mode is in core already. You just need to toggle its state.
leymannx avatar
ne flag
Yeah, cron job on server level which activates/deactivates maintenance mode using Drush commands. Maintenance page can be customized. All good.
leymannx avatar
ne flag
And then have the permission to use the site in maintenance mode removed from this role.
ro flag
I know about the Maintenance section in drupal admin but I want to down site for perticular time interval 12:00 am to 12:30 am
Score:1
ch flag

and welcome to StackExchange.

As stated in the comments on your question, you are essentially asking for Maintenance Mode, which is part of Drupal core. In your site, go to /admin/config/development/maintenance and look at the settings there. You can turn on Maintenance mode, and set the text that is shown to unauthorized users. There is also a permission setting (found on the permissions page) to still use the site in maintenance mode, in case you want to make edits while others cannot access the site.

To have this happen automatically based on time, you will want to use Cron. That is what Cron was built to do, so it is a perfect fit. In order to use Cron for this, you will need a handy bit of code that can do the same thing as the checkbox in the maintenance ui. Drush is a very powerful tool, and can do almost anything. To turn maintenance mode on, you could run this:

drush state:set system.maintenance_mode 1 --input-format=integer

That command is found and explained on this page. Now, you need to have that command run by cron instead of by a human on the server command line. Fortunately for you, Drupal has a long history of dynamically using custom code that you add, as long as the name matches. That is the hook system, where custom modules and functions matching certain patterns are called at certain times. You will want to create a custom module that uses hook_cron() to run that drush command at the designated times.

And finally, always clear cache before thinking something is broken.

ro flag
I know about the Maintenance section in drupal admin but I want to down site for perticular time interval 12:00 am to 12:30 am
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.