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
-
This website is created in drupal8.x– Manoj PatilCommented Oct 19, 2021 at 12:17
-
1Im sure there are several modules for this. Maintenance mode is in core already. You just need to toggle its state.– KevinCommented Oct 19, 2021 at 12:40
-
1Yeah, cron job on server level which activates/deactivates maintenance mode using Drush commands. Maintenance page can be customized. All good.– leymannxCommented Oct 19, 2021 at 13:57
-
1And then have the permission to use the site in maintenance mode removed from this role.– leymannxCommented Oct 19, 2021 at 17:55
-
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– Manoj PatilCommented Oct 21, 2021 at 5:15
1 Answer
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.
-
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 Commented Oct 21, 2021 at 5:16