MaintenanceMode

From Request Tracker Wiki
Revision as of 09:39, 16 July 2019 by Phanousk (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Here's a quick and dirty Maintenance Mode. If you need to block access to the web site for any length of time (to back up the database, for example) this lets you block access to the site without needing to bring the site down or clear out the Mason cache. And it's as simple to unblock the site, too.

When the new code is in place, you can place the site into maintenance mode simply by creating a file called ".maintenance" in the root of the RT install:

# touch /opt/rt3/.maintenance
 
 

and taking it out of maintenance mode is as simple as removing the file:

# rm /opt/rt3/.maintenance
 
 

The effect is instantaneous in both cases. See below for how to customize the message.

To enable this, make the following changes:

<pre>
# create the directory <rt-root>/local/html/NoAuth, if needed
# create the file <rt-root>/local/html/NoAuth/Maintenance with the contents shown below
# copy the file <rt-root>/share/html/autohandler to <rt-root>/local/html, if needed
# add the following line to the top of your local autohandler, just under <%INIT> (be sure to change /opt/rt3 to whatever your RT root is):

 $m->comp("/NoAuth/Maintenance", FName => "/opt/rt3/.maintenance") if (-f "/opt/rt3/.maintenance");
</pre>

Clear the Mason cache after doing this to see the effects of the changes (see CleanMasonCache for how to do that). Run the touch command as above to put your site into maintenance mode.

<rt-root>/local/html/NoAuth/Maintenance

<pre>
 <html>
 <head><title><% $title %></title></head>
 <body>
 <div id="header">
 % if ($html) {
 <% $maintmsg|n %>
 % } else {
 <h1><% $maintmsg %></h1>
 % }
 </div>
 </body>
 %$m->flush_buffer();
 %$m->abort();
 
 <%args>
 $DefMsg => "The system is down for maintenance.  Please check back in a couple of minutes."
 $DefTitle => "RT Maintenance"
 </%args>
 
 <%INIT>
 $m->clear_buffer();
 
 my($rc) = open(IN, "<$FName");
 if (! $rc) {
    my($errmsg) = qq([Maintenance] Cannot open "$FName" for input - $!);
    $RT::Logger->crit($errmsg);
    $m->print("<strong>$DefMsg</strong><br/ ><br/ >");
    $m->print($errmsg);
    $m->abort();
 }
 
 my($maintmsg) = "";
 my($title) = "";
 my($html) = 0;
 
 {
    local $/;
    $maintmsg = <IN>;
 }
 
 close IN;
 
 if ($maintmsg =~ m{\[HTML\]}) {
    $html = !0;
    $maintmsg =~ s{\[HTML\]}{};
 }
 
 if ($maintmsg =~ m{\[TITLE ([^]]+)\]}) {
    $title = $1;
    $maintmsg =~ s{\[TITLE ([^]]+)\]}{};
 }
 
 $maintmsg ||= $DefMsg;
 $title ||= $DefTitle;
 </%INIT>
 
 <%ARGS>
 $FName
 </%ARGS>
</pre>

The actual message to be displayed will be taken from the contents of the .maintenance file itself. If the file is empty, it will use the default message. You can also customize the HTML Title shown, by putting "[TITLE Some Different Title Here]" in the .maintenance file. This will be stripped out before the main message is displayed. Finally, if the message in the .maintenance file contains HTML, you can have it pass through as-is by putting "HTML" in the .maintenance file (again, it will be stripped out before the message is displayed). For example:

[TITLE Emergency Maintenance]
The RT site will be down for emergency maintenance for the next 15 hours!
If this is an emergency, please open up a ticket with a Priority of 99.
[HTML]

This was tested on RT 3.6.3; let me know if you have any problems. -- JoeCasadonte

Note: reports are that this does not work under 3.4.6