Is there a module (or other way) to give permission to non-admin-users to put the site offline (and only that permission)?
5 Answers
There is a module for that!
Placing a site in or removing it from maintenance mode is allowed under a permission that has wide spread administrative access (administer site configuration). Sometimes you'd like to give permission to put the site in maintenance mode to someone but not give them complete access. This modules enables this case.
On D6 and D7, there's no specific permission to give to a role to grant access to the Maintenance mode page (admin/config/development/maintenance). This is because it has the "Administer site configuration" that grants access to many other configs that important and should be restricted only to a few users/role.
You can use Drush to do it:
drush vset maintenance_mode 1
Or create a new permission for that path (admin/config/development/maintenance) with hook_alter_menu:
function {your module}_alter_menu(&$items) {
// Site maintenance
$items['admin/settings/site-maintenance']['access arguments'] = array('administer maintenance mode');
}
To create the new permission use hook_permission:
function {your module}_permission() {
return array(
'administer maintenance mode' => array(
'title' => t('Administer maintenance mode'),
'description' => t('Perform administration on maintenance mode page.'),
)
}
At the very end of sites/default/settings.php, add the code below:
$conf['maintenance_mode'] = 1;
Remove the line of code above, or change the value to 0 to put your site online again:
$conf['maintenance_mode'] = 0;
Thats all
For Drupal 7/8/9 you can use the module Custom Permissions for that.
You have to (Drupal ^8):
- Install the module Custom Permissions
- Go to settings page /admin/people/custom-permissions/list
- Set the "Custom Permission" for Route "system.site_maintenance_mode"
- Find and set your permission on /admin/people/permissions
That's it.
(If you have installed Devel, you can find a list of routes on the page /devel/routes)
You would need to give the permission "System > Administer site configuration". You can give that permission basically to whatever role you like. This lets users with that role put your site into Maintenance Mode. But be aware that this is a very powerful permission and it comes along with other administrative rights. Also – if you give that permission to a role you should probably also give the permission to view the site, if it's in Maintenance Mode.
I would consider such practice actually a security risk and would recommend to only give that permission to an extra role like "co-admin" or the like.
Edit: there's a module that let's you split administrative permissions into smaller chunks called Custom Permissions. The project page also gives a good impression which administrative rights are connected to the permision "System > Administer site configuration".
"By default the following permissions are created:"
administer administration theme
administer clean-urls
administer date-time
administer error reporting
administer file system
administer modules
administer performance
administer site information
administer site maintenance
display site building menu
display site configuration menu
variable_set("maintenance_mode",1);
To put the site online For D7variable_set("maintenance_mode",1);
For D6 it isvariable_set('site_offline', '0');