Theming the Drupal 6 maintenance page

Last modified: June 30, 2009 - 04:09

The maintenance page is used when the site is set into off-line mode or site is inoperable due to technical problem such is database server not working. You can enable this mode from "Administer > Site configuration > Site maintenance". This mode will also trigger with a database failure. By default, the core theme Minnelli is used in this mode even if another theme is selected. To use your theme for the maintenance page, it has to be set from your "settings.php" file located in either "sites/default" or "sites/your.domain.com".

From that file, enable it through the $conf variable with the internal name of your theme:

<?php
$conf
['maintenance_theme'] = 'themeName';
?>

Instead of adding the line above to the settings.php file, you can also uncomment (remove the hash at the start of the line) the relevant lines in settings.php. In that case, you have to uncomment 3 separate lines :

  • the array declaration (# $conf = array()
  • the maintenance theme setting (#   'maintenance_theme' => 'minnelli',)
  • the closing parenthesis (# );)

Next, copy your main "page.tpl.php" and rename it to "maintenance-page.tpl.php" or copy the template located in "modules/system/maintenance-page.tpl.php" to your theme and edit so it matches the rest of your site. Verify the changes by setting the site into off-line mode then log out.

To account for database failures, try turning off your database. Any function call that depends on the database should be checked first with db_is_active. The variable $db_is_active can also be used from the template. As an alternative to disabling your database, force a database connection failure. Examples for both methods here.

To prevent warnings about the database connection from appearing, you can also place a template file named "maintenance-page-offline.tpl.php" and change the $content variable with your custom message. This template file is a template suggestion based on maintenance-page.tpl.php so they both need to exist.

You might also want to set:

  • $head_title - the value used in the HTML <title> tag. Defaults to "Site off-line | Drupal"
  • $site_name - value used in the page's <h1> tag. Defaults to "Drupal". If "Site name" is turned off in your theme configuration, then you'll want to clear this variable (see example below).
  • $logo - if you're using a custom logo override in the theme settings. Use the full path of the custom logo, relative to the base directory of the Drupal installation. If you used the standard override upload function in the theme configuration for your custom logo, your logo will be stored in sites/all/files/ (see example below).
  • $site_slogan - Your site's slogan. If "Site slogan" is turned off in your theme configuration but you still have a site slogan defined in Site Information, then you'll want to clear this variable (see example below).

Example additions at the top of maintenance-page-offline.tpl.php:

<?php
$head_title
= 'mysite.com :: Site-offline';

$logo = 'sites/all/files/customLogo.png';

// If your  theme is set to display the site name, uncomment this line and replace the value:
// $site_name = 'Your Site Name';

// If your  theme is set to *not* display the site name, uncomment this line:
unset($site_name);

// If your theme is set to display the site slogan, uncomment this line and replace the value:
$site_slogan = 'My Site Slogan';

// If your theme is set to *not* display the site slogan, uncomment this line:
// unset($site_slogan);

// Main message.  Note HTML markup.
$content = '<p>The site is currently not available due to technical problems. Please try again later. Thank you for your understanding.</p><hr /><p>If you are the maintainer of this site, please check your database settings.</p>';
?>

A "maintenance.css" file is included in this mode. It is located in "modules/system/maintenance.css". You can override this file with the instructions provided in the style sheets section.

Notes:

  • The initial install and updating of your site depends on the core themes, Minnelli and Garland. It cannot be changed for these modes.
  • The theme registry is not cached when set to off-line mode.
  • Ensure that the theme used as maintenance theme is enabled (Administer > Site building > Themes).

Theming the Drupal 6 maintenance page-drupal.org/node/195435

SDM-MINK - March 4, 2009 - 19:11

I am new to Drupal, so I am probably making a mistake. I am trying to change the Theme of my Drupal 6 maintenance page so that it matched the theme (mytheme) that I am using for my site (Theming the Drupal 6 maintenance page - http://drupal.org/node/195435).

I tried to followed the instructions shown in http://drupal.org/node/195435. Here are the problems that I had:

1. Got message that sites/default/settings.php was password protected so that I could not make changes to this file. So I made changes to the sites/default/default.settings.php. However, when I went to upload the modified file onto my server, I received a message indicating that sites/default/ was locked and thus would not accept this modified file.

2. Am I to save the new file maintenance-page.tpl.php in theme/mytheme or write over the file located in modules/system?

3. I could not find any directions as to how to modify modules/system/maintenance.css. I assume that I should take my style.css (in theme/mytheme), rename it maintenance.css then write over the file located in modules/system. Is this correct?

However, since I could not perform 1 above, I am still using the default ("minnelli") maintenance page.

Any assistance is much appreciated! Thanks!

The settings.php file is

mattyoung - March 9, 2009 - 05:04

The settings.php file is write protected for security reason. You need to temporarily turn on write permission to that file to make change. On Unix/Linux you would do chmod u+w settings.php, edit/save, then chmod u-w settings.php.

hi, how do you turn off the

annicole72 - March 20, 2009 - 21:13

hi, how do you turn off the database?

thanks.

Re: how do you turn off the ...

SDM-MINK - March 20, 2009 - 23:18

Do you mean "turn off the theme & turn on the maintenance page" or "turn off the maintenance page"?

I guess...

panatlantica - April 8, 2009 - 16:07

I guess you mean "how do I turn off the database to see what happens to my site". In order to do that, you really would need full server access, it usually cannot be simulated with typical shared hosting plans.

On a dedicated server: if you use the Plesk control panel, you can go to Server -> Services and switch off MySQL. Don't worry about Plesk, it runs on its own DB-server and own Webserver, so whatever happens, Plesk should remain accessible. If you don't run a control panel, you need to log in as root via SSH (or do it locally in the terminal if you have physical access to the server). Then issue

/etc/init.d/mysqld stop

The Database server will shut down and tell you so. Now you can test your Drupal installation and test what happens if no DB-server can be found any more. The normal and unaltered behaviour of Drupal is to spit out a page in the standard maintenance design saying that such and such database on server such and such with username such and such (sic!!!) is not available.

Thanks god Drupal does not tell the database password!!! This is a good ment feature for the site admin in case things go wrong (like the DB server died by some reason) but it is a bit awkward on public and live sites where such things might also happen... I mean you don't get far with this information, but non-the-less, the general public now knows where the database server is located, what Drupal's database is called and which username is chosen to access the server... :-(

This is basically the reason why DB-offline maintenance themes should be done on larger scale sites. To provide a clean information that something has gone wrong. :-)

After your test (seeing if your new DB-offline page actually works in such situations), don't forget to switch back on the DB-server, either using Plesk or on the command line with

/etc/init.d/mysqld start

Just as a note: should in your distro the terminal tell you that there is no file in /etc/init.d called mysqld, you might want to search for it on the machine, it will usually be somewhere in a subdirectory that controls the services to start upon system startup. On some Linux systems, there is the even more elegant command

service mysql stop
and
service mysql start

Simulating database failure to test maintenance-page-offline

kentr - April 30, 2009 - 05:51

Instead of actually disabling the database, you can just intentionally cause a failed connection.

Do this by making the connection string invalid in settings.php:

  • At the very bottom of the file, add:
    $db_url = 'x';

This should cause a failed database connection and invoke the maintenance-page-offline.tpl.php file.

When you're done testing, remove that code. It should set everything back to normal.

Thanks, this worked nicely.

Zoologico - April 14, 2009 - 17:56

Thanks, this worked nicely.

subscribing

Ascenti0n - April 17, 2009 - 14:01

subscribing

 
 

Drupal is a registered trademark of Dries Buytaert.