I have several website stored on a server.
If I want to upgrade my apache configuration I want to inform all my customers that there will be an upgrade in 30 minutes.
I can modify each website to show this message but I was wondering, how can I make it automatic ? What's the professional way to do it ?
Also, when Apache is restarting or upgrading, there will be no "Maintenance page". How can I instead show for each website a default page "under upgrade" if apache is down ? Do I need 2 servers ?
During the phase where you upgrade all your packages, you just keep apache running and nobody will notice.
The actual restart of apache can be done in such a manner that individual users won't notice that either, by using a graceful restart. This will allow each worker thread to complete serving the current page and then not accept new requests. Then the server reload, which only takes a few seconds, and starts serving requests again.
That's not your problem. The problem is what to do if something does go wrong. In which apache won't restart, and the n your user will notice. So you want to make sure that nothing can go wrong.
And the way to do that is to create an exact mirror copy of that web server on another machine, then do the upgrade there and see what happens. Make a note of all the things that need a manual fix or intervention before apache is restarted. Then repeat the whole process until you have a completely smooth operation. And then and only then you do the upgrade on the live server.
You need some additional capability over just serving static content - you could do this using server side includes or a PHP auto-prepend or roll your own solution using the language you develop your site in. Then just change the content of the file you are including. However this is not a trivial exercise - to support this you would need to ensure that html content served is non-cacheable (or has a very short cache time). Also, if you use the PHP route you can't just write the output straight to the browser if you need to use cookies / sessions / redirection.
This is much MUCH more complicated. Given that restarting your Apache instance shouldn't take more a few seconds its not worth the effort. If the restart takes more than 5 seconds, then you've got a different problem to fix.
There are any number of ways to do this, but I might make a recommendation to do this with Javascript.
You could embed a script on each site at any time. Have the script check a URL on your server, it can be simply a text file with a 0 or 1, or you can put a message in there (JSON is a good protocol to use). Have the script, client side, check a URL for that variable. If it is 1, display the message, if it is 0 do not. You might even want to encode the message in that text file in case you need to display some message to all of your website users about a delay or any other information.
When you are ready to make the migration, 30 minutes prior, have the Javascript launch a notification bar at the top of the sites, notifying users that the site will be upgraded shortly.
You can get as fancy as you want with it, but in my head this is the best way to do this for a number of sites. Of course, if you have a lot of hits at any one time, that is a lot of clients checking that URL. It just depends on your particular situation. You could also do it server-side with some caching.
You can use mod_layout to add custom HTML or PHP code to the start or end of pages. See the mod_layout FAQ for a good overview of how to use the mod but it can be as simple to use as: