views:

1240

answers:

4

I have a website running on a Linux/Apache/Tomcat stack that needs to be automatically taken offline every few months for server maintenance, which will last an arbitrary amount of time. What are some options for getting Apache to put up and take down a "server maintenance" page?

I need to be able to control this via shell script. (The answers that Google provided revolve around manually editing the server configuration, and I don't want to be in the office at 3 am!) I suppose I could make the script drop in an .htaccess file and delete it when it's done, but that seems less than graceful.


Answer commentary:

xsaero00's answer looks like the best-practices answer, although what I'll do is probably more like Dan's answer because the third-party hosting provider controls the load balancer and I don't want to deal with that mess. Thanks!

+1  A: 

make 2 config files and swap them back and forth

If only a little bit of the file will change, merge them with come sort of preprocessor and generate both the standard and the "off-line" versions from one source and swap between those.

IIRC the apache config files are build using CPP anyway

BCS
A: 

We have done something similar. We have an index.html that redirects to our main site page. When we have maintenance we run a script that changes the redirect in the html file. Then we through the script in cron and viola automatic maintenance window.

Hope that helps!

+2  A: 

it's pretty easy to start up Apache with a custom config file. On my system:

httpd -f <config>

I use this regularly in combination with a shell script an an extremely simple config as a maintenance placeholder. The script simply stops my regular Apache, and starts this.

Dan
+4  A: 

We have a setup that does just that but it includes more than just apache. There is a loadbalancer and two servers behind it. Both web servers serve website using Apache and one of them has an additional virtual host that serves simple HTML maintenance page. The load balancer has a virtual HTTP service that redirects requests to real servers. This virtual service has three real servers: two are actual servers and third is a virtual IP on second server that points to maintenance page. The real servers are weighted with third having the least possible weight and the load balancer uses fixed weighting algorithm. So when real websites go offline for any reason all requests go to maintenance host and users see the nice error page with a phone number. In fact I use a small script to check the health of real servers, so the maintenance page displays as soon as there is any sign of trouble.

PS. I use Load Master 1500 for loadbalancer.

xsaero00