APLawrence - Information and Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds Get APLawrence.com by RSS











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Home > Programming > Power failure changes my habits
Printer Friendly Version




Power failure changes my habits



More than 90% of this website is controlled by one Perl script. That script reads content, surrounds it with style sheets and everything else it needs, and spits it all out for you, the reader.

Obviously that script is pretty darn important, and usually.. usually.. I'm very careful about changes I might make to it. I make a copy, edit the copy, and test the new code on a subset of pages. If I have made some horrible mistake, I fix it or revert back to what I had.

OK, that works, but sometimes a change is just so simple, it hardly seems worthwhile to go to all that trouble. Heck, it's just one or two lines I'm changing, I'll just edit the file directly. No problem, right?

Yeah, right. The other night I had a simple little change like that. I vi'd the script, wrote it back out, and poof.. website down.. or at least the 90% that depends on that script. I had made a stupid typing blunder that caused a syntax error in the code and of course that was the end of that. Easily fixed: back into vi, fix the typo, write it back out, and ayup, everything is fine. No real harm done, maybe a half dozen visitors got a momentary server error - not a great thing to do to people, but no lasting damage.

And then not fifteen seconds later the power went out at my home.

Of course the website was still up. That's in a data center somewhere, well protected with generators and redundant internet connections - that runs for years between reboots. But I couldn't get to it because my power was out and my router wasnt working.

If I had my router on a UPS I actually might be able to: my Verizon FIOS has a battery backup so I assume that if I had power to the router (and my switch, etc.) I could still work. But I don't bother with that: power failures aeren't all that frequent and I need a break now and then anyway. It's not all that important..












Or is it? Suppose that failure had happened just after I had written out the file with the typo? My site would have been down until the power came back on and I could fix it. In this case, that was hours later.. that would have ticked off a lot of people.. me most of all!

OK, I'm convinced: I probably need a UPS. And I probably should always stage my changes through a test copy. But realistically, that's not going to happen.. I know darn well that if it's "just a little change", I'm not going to do that. So I needed something else to help protect me from my own stupidity.

With Perl, that's not very difficult. I wrote a little script called "vpage" that looks like this:

#!/bin/sh
file=$1
cp ~/cgi/$file ~/stage/$file
vi ~/stage/$file
perl -c ~/stage/$file && cp ~/stage/$file ~/cgi/$file
 

For those "simple" changes, this protects me from typos that break the script dead: if the "perl -c" fails, the file will not be overwritten.

That's no replacement for staging changes. It does acknowledge reality though: I'm not always going to follow protocol even when I know that I should. Now consider this for a moment: I own this website. It's very important to me. I'm not an employee, not hired help: if I can't guarantee that I won't sometimes take shortcuts, how much more likely is it that someone with a lesser interest might do the same? Moral: your systems should anticipate laziness and haste on the part of humans and should try to protect themselves as much as possible.

I'll pick up a UPS soon. I'll also try to more conscientious about testing my changes, but when I'm not, I'll at least use that script rather than editing directly.


If this page was useful to you, please click to help others find it:  

Your +1's can help friends, contacts, and others on the web find the best stuff when they search.

Comments?




More Articles by Anthony Lawrence - Find me on Google+



Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

My Hard Truths about Easy Money on the Internet will show you how to make money on the Internet!

book graphic Internet Income guide



 I sell and support
 Kerio Mail server
pavatar.jpg

This post tagged:

       - Blogging
       - Perl
       - Programming
       - Scripting
       - Shell




Unix/Linux Consultants

Skills Tests

Guest Post Here