In Drupal 8, the Site Maintenance status is stored in State API. To put Site in Maintenance mode or to get Site out of Maintenance mode, we can use following code snippet:
  \Drupal::state()->set('system.maintenance_mode', 1);
  // Clear render cache to make sure user are not able to access site.
The value 1 specify maintenance mode is enabled and 0 specify maintenance mode is disabled.


Submitted by ychaugule on