On Tue, 13 Jun 2000, Erich L. Markert wrote:

> I'm trying to figure out the best way to make apps (un)available without
> having to edit the apache config files.

We did something like this by making a handler like this:

 package Foo::PerlHandler;
 
 use Class::MethodMaker
     new_with_init => 'new',
     get_set       => [qw/request/];

 sub handler {
     my ($class, $r) = @_;
     ($class, $r) = (__PACKAGE__, $class) unless defined $r;
 
 
     if (-f /tmp/foo.unavailable) {
          $r->headers_out->add('Location', '/maintenance/index.html');
          return REDIRECT;
     }

     my $this = $class->new($r);
     $this->service;
 }

 sub init {
     my ($this, $r) = @_;
     $this->request($r);
 }

 sub service {
     die "service is virtual!\n";
 }
 
 __END__
 
Then in our actual apps, we inherit Foo::PerlHandler:

 package Foo::MyApp;
 
 use Foo::PerlHandler;
 @ISA = qw(Foo::PerlHandler);
 
 sub handler {
     my ($class, $r) = @_;
     ($class, $r) = (__PACKAGE__, $class) unless defined $r;
 
     # do pre-request things specific to Foo::MyApp

     return $class->SUPER::handler($r);
 }

 sub service {
     my ($this) = @_;
     my $r = $this->request;

     # do whatever here that you would do in your handler.
 }
 __END__

In httpd.conf:

<Location /foo/myapp>
    SetHandler perl-script
    PerlHandler Foo::MyApp
</Location>

In actuality, we usually dont have to even define a handler() in our
application classes because the one provided by Foo::PerlHandler does
everything we need.  Occasionally it is useful to do overload it though (which
is why I show the simple example above.

The benefit of this is that as long as all of our applications make use of
Foo::PerlHandler as their parent class, then we can shut down all applications
and make them redirect to /maintenance/index.html by simply doing "touch
/tmp/foo.unavailable" on the web server(s).  No need to restart, no need to
fiddle with config files.

To make the applications available again, just "rm /tmp/foo.unavailable" and
requests are not redirected to the maintenance page anymore.

Anyways, this is how we decided to deal with this issue.  Theres lots of other
ways I am sure :).

Mike

Reply via email to