Tag Archives: server

Server Down

The server will be down tonight for several hours. It’s going to Zack’s party, and will likely drink way too much. Hopefully, it will be back up and on the job early in the morning, and won’t be forced to take a personal day.


Up/Down Server Maintenance Page

This last week was a nightmare ye olde’ Addison Road server. Hardware failures, network problems, torn ligaments, data loss. Several times this week, I found myself having to shut the site down and put up a maintenance holding page.

I’m a lazy person. If I find myself doing something more than once, I’ll spend 5 or 6 hours finding a way to automate it, so that I never have to do it by hand ever again. Maybe not a good use of time, but certainly a good use of … I dunno, beer? Anyway. This is for the hobby geekers and tweakers out there, who run their own sites on servers that allow them SSH access. Suppose your site gets really slow, and you want to keep users off while you tweak. Or, maybe you’re upgrading your wordpress install, changing themes, whatever, and you don’t want your undies exposed while you do it.

Here’s how I do it.

I keep two files in the root folder of my site, index.php (it’s a wordpress site, built with php, so that’s the extension, not html), which is my normal, everyday functioning index page. The second page is named index.down.php, and it contains a simple error message to let people know that I know that the site is all hinky. In fact, you can check it out if you go there now. When my site is down for maintenance, I want to rename that page index.php, so that it shows up instead of my normal index page. I also want to rename my normal index page to index.bak.php, so that I don’t lose it. I want it all to happen with no downtime.

Pop open the .bash_profile file located in the home directory of my server. I’ve added the following two lines (ignore all of the line breaks here – enter everything on one line, anywhere in the file).

First line:
alias ard.down="mv ~/addisonrd.com/WordPress/index.php
mv ~/addisonrd.com/WordPress/index.down.php

Here’s the second line:
alias ard.up="mv ~/addisonrd.com/WordPress/index.php
mv ~/addisonrd.com/WordPress/index.bak.php

So what are you commanding the automagic computer machine to do? ‘Alias’ means that you only have to type the short word, and the shell will execute the long command. There’s really only one command here – mv means move, but since locations are names, it also works to rename your files. The secret sauce is the semi-colon. It tells the computrix to execute the first command, then immediately execute the second command. Since this happens almost simultaneously, that makes it pretty much an instant name swap.

You’ll have to exit out, then log back in before the aliases in your .bash_profile file will work.

Once these two commands are in place, putting up a maintenance page is a simple as logging into your server via SSH, and typing ‘ard.down’. It renames the files, in an order that won’t overwrite either one, and with no downtime at all.

The advantage of this while I’m tweaking on my site is that I can still see the site, just by entering the direct URL to ‘addisonrd.com/WordPress/index.bak.php’.

Once I’ve finished whatever I’m working on, I enter ‘ard.up’, and the files are flipped back to their original names, just like that.

Candy, baby. Nothing but pie.