Many sites use a more complicated setup in which a "light" Apache frontend server serves static content but proxies all requests for dynamic content to the "heavy" mod_perl backend server (see Chapter 12). Those sites can use a third solution to temporarily disable scripts.

Since the frontend machine rewrites all incoming requests to appropriate requests for the backend machine, a change to the RewriteRule is sufficient to take handlers out of service. Just change the directives to rewrite all incoming requests (or a subgroup of them) to a single URI. This URI simply tells users that the service is not available during the maintenance period.

For example, the following RewriteRule rewrites all URIs starting with /perl to the maintenance URI /control/maintain on the mod_perl server:

RewriteRule ^/perl/(.*)$ http://localhost:8000/control/maintain [P,L]

The Book::Maintenance handler from the previous section can be used to generate the response to the URI /control/maintain.

Make sure that this rule is placed before all the other RewriteRules so that none of the other rules need to be commented out. Once the change has been made, check that the configuration is not broken and restart the server so that the new configuration takes effect. Now the database server can be shut down, the upgrade can be performed, and the database server can be restarted. The RewriteRule that has just been added can be commented out and the Apache server stopped and restarted. If the changes lead to any problems, the maintenance RewriteRule can simply be uncommented while you sort them out.

Of course, all this is error-prone, especially when the maintenance is urgent. Therefore, it can be a good idea to prepare all the required configurations ahead of time, by having different configuration sections and enabling the right one with the help of the IfDefine directive during server startup.

The following configuration will make this approach clear:

RewriteEngine On

<IfDefine maintain>
    RewriteRule /perl/  http://localhost:8000/control/maintain [P,L]

<IfDefine !maintain>
   RewriteRule ^/perl/(.*)$ http://localhost:8000/$1 [P,L]
   # more directives

Now enable the maintenance section by starting the server with:

panic% httpd -Dmaintain

Request URIs starting with /perl/ will be processed by the /control/maintain handler or script on the mod_perl side.

If the -Dmaintain option is not passed, the "normal" configuration will take effect and each URI will be remapped to the mod_perl server as usual.

Of course, if apachectl or any other script is used for server control, this new mode should be added so that it will be easy to make the correct change without making any mistakes. When you're in a rush, the less typing you have to do, the better. Ideally, all you'd have to type is:

panic% apachectl maintain

Which will both shut down the server (if it is running) and start it with the -Dmaintain option. Alternatively, you could use:

panic% apachectl start_maintain

to start the server in maintenance mode. apachectl graceful will stop the server and restart it in normal mode.