What is the best method for taking a site down and kicking out users to do an upgrade?

0 votes
asked Mar 19, 2009 by darryl-hein

I'm wonder how people are kicking people out or blocking access to a site when you want to do an upgrade and you have users that are logged in.

My one thought is to just put a bool setting in a global file (such as the settings file) for whether or not the site is unavailable. True is available, while false is unavailable. When false, the next time the user attempts to access the site they will either be logged out or just presented with an unavailable message.

There are 2 issues I can see with this method:

  1. If users are just finishing filling in a long form or writing a large portion of text (like a new question or answer on SO), as soon as they submit the form, they'd lose that information. (Can't always save it, because there maybe DB changes for that table or code may have changed already.)

  2. Possible: On a busy site, editing the global file if it's more than a couple lines it might cause PHP parse errors if that page is loaded while it's partially uploaded or while saving. There might also be locking issues on the file, depending on the configuration.

Another option is to have a field in the database with the same setting. At the moment, I don't generally have a table for settings, so this would be the only thing in the table, but I could see it being faster as it avoids the second problem.

Is there something that you've used that worked well or any other ideas?

I'm working with LAMP.

6 Answers

0 votes
answered Jan 20, 2009 by slolife

What about just not allowing new users to log in, and monitor the number of logged in users until it is reaches 0, and then you can upgrade?

0 votes
answered Jan 20, 2009 by virtuosimedia

Inform the users in advance that your site will have downtime at a specified time and then perform the upgrade at your least busy hours according to your log files. Weekends work great for upgrading if your site is business critical to your users. A little downtime on a Sunday morning at about 3am probably isn't going to anger too many users. Just make sure that you have everything you need in place before you do the upgrade so that you can minimize the downtime. You might even consider doing a dry run on a test server.

0 votes
answered Jan 20, 2009 by stunti

If your system is session based, an easy way is to change the session name. The cookie name will change and nobody will get the new one until they log in again.

0 votes
answered Jan 20, 2009 by nickf

This one is similar to Bobby's suggestion. The way I achieved the same sort of thing is to put a couple of values in to a "config" table in the database, one is the date/time to take the system down, and the other is a message.

Once the date field is not null, then block all logins, and on every page refresh, just use a javascript alert to display the message to users explaining that the site will be taken down in X minutes, for Y reason and should be back online in Z minutes. This is an annoying and in-your-face way to do it, but it's really quite important that they realise that they shouldn't start filling in a really long form.

Once it's after that maintenance start time, then boot all users on their next page refresh. ...except for admins, of course.

Getting all the clients to periodically poll the server to check for an impending maintenance period is overkill, IMO. If you do have a couple of pages which have really long forms, then perhaps add the AJAX polling just on those ones.

Having these sort of values in the database is easy to implement, is quite flexible, and is perfect for this situation.

0 votes
answered Mar 20, 2009 by bobbyshaftoe

You could implement a status field, perhaps an AJAX style one like the orange bar at the top of StackOverflow pages, that informs the users that the site will be going down in 10-15 minutes or what have you. You could also disable logins during that time. Then just bring the site down completely, do your upgrade, and bring it back on line.

0 votes
answered Mar 20, 2009 by sepehr

You might want to utilize a webserver redirect. In case of Apache, a .htaccess file to redirect (or rewrite url) users to a static maintenance page:

RewriteRule ^updating.*$ $0 [NC,U,QSA,L]
RewriteRule .* /updating/ [NC,U,QSA,R=307,L]

In case you want to access the site yourself when in the maintenance mode, you can attach a specific and hopefully-unique string to the useragent header:

RewriteRule ^updating.*$ $0 [NC,U,QSA,L]
RewriteCond %{HTTP:User-Agent} !MY-CUSTOM-UA-STRING [NC]
RewriteRule .* /updating/ [NC,U,QSA,R=307,L]

Here's how to manipulate your user-agent in firefox:

Create a new about:config key named general.useragent.extra.XYZ and set it as "MY-CUSTOM-UA-STRING" or anything else you wish. Firefox will attach the string to the UA.

If using Chrome, try the new Mobile Emulation feature which allows you to modify the user-agent string directly from the devtools.

As you've mentioned yourself, an alternative solution could be setting of a config flag on the server side. Before making so, I suggest that you save all the user's ongoing operations on the site and let her resume them after the maintenance period. Also, let them know the exact time of maintenance beforehand.

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...