Posts Tagged ‘web dev’


Backups or The Dreaded `rm -rf /*`

Thursday, July 29th, 2010

At my startup, we have a moderately sane deployment environment. Check-ins are automatically pushed to a staging server (And i’m notified via notifo with this script). When we want to push code to our live server, we manually move things.

For a while that meant we had to run a

svn export

command by hand once a day or so. (we are under heavy development still)

Eventually we needed a couple more things done when we moved code to the live server (among them run google’s closure compiler to reduce our js footprint). So I wrote a script to handle these things. Apparently while testing, I got distracted and never finished it, because when i ran it, the code was this:

# ... snipped ...
#
# code to assure you're running as root
#

if [ -z $2 ]
    then
        loc= '/path/to/code'
    else
        $loc = $2
fi

# nuke old files
rm -rf $loc/*

# ... snipped ... 

Now, to the astute, you will notice there is a bug here. Can you find it? It’s in the assignment of

$loc = $2

It SHOULD be similar to the loc assignment above it.

loc=$2

Well. This throws an error, but happily keeps moving on down the script. Next question: what happens here when $loc is an empty string ”? That’s right. I just ran rm -rf /*as sudo on our main server.

I realized quickly what had happened. Errors whizz by about permissions, and finally I Ctrl+c’d it out of existence. Everything still in memory was intact. Our application was still running, I was still ssh’d in. So I took stock of my life, and tried to calm down. I had no idea what to do at this point; thoughts ranged from spending the next 12 hours slowly rebuilding everything (I had the latest copy of our code and db on my local computer, so our code was safe) to never returning my CEO’s emails again and abandoning our company. I initially did some fruitless googling for ‘restore rm -rf *’ even though I knew – short of serious hard drive-level manipulation – I was NOT getting anything back.

Then I remembered that we are using Jungle Disk to do daily and weekly backup. I figured out that Media Temple (our awesome host) allows us to reinstall our OS if something like… this happens. So first I checked that we had a recent backup. We did. So i went into our dasboard, and clicked on the button to ‘Revert to Default’ (MT’s oh-shit button). And waited. After that was done, the first thing I reinstalled was Jungle Disk and set it up to recognize itself. Then I simply ran Jungle Disk’s restore program, and voilà! I installed a few more programs that we needed, and we were 100% back up and running in about 3 hours.

We back up our /etc, /var, and /home folders daily and our entire file system weekly, so not too much data was lost. As it turns out, this doesn’t include our Postfix maildir, so we lost about a week’s worth of email (personally, I use gmail and it downloads all the email, so I didn’t lose anything). We have since fixed this to save email daily.

This story is another among many to remind you to back your shit up. Fortunately we ended up ok; thanks in no small part to Jungle Disk.

If you have any questions about our staging=>live process (which is now Idiot Proof©), or our backup strategy, drop me a line at hello at andrebluehs dot net.


Coffin Nails and Native Mobile Apps

Friday, June 4th, 2010

One of my startups, Usable Health, is making an iPad-specific version of our web app to be installed in restaraunts. (Side note: watch our CEO talk at Ignite Atl) Since we were going to set-and-forget these applications, we needed a way to prevent people from going to other sites (as this is a web app just running in safari). Then I came across this article by Alex Kessinger. And we realized:

We wanted a native iPad app. So we made a web app.

Alex’s article gets in to a bit too much detail for us. We really only need one line:

<meta name=”apple-mobile-web-app-capable” content=”yes” />

This one line of code transformed our web app (built for ipad size and features) into a native-looking app with no Safari toolbars on the top or bottom. Add it to the home screen, and you are off and running.

There are other features of that post that we could use, such as setting a home screen icon, but we don’t care about this, because our app should never be closed anyway while at an installation.

Here are screens of before:

after:

The total time from start to finish to get this working? 26 minutes. This includes me sharing the link, and our developer reading the article.

This is why i believe that for most applications, native apps are becoming obsolete. There are HUGE incentives for more adoption of this method:

  • no need for apple developer licence (cheap for small companies)
  • don’t have to deal with the app store

There are, however, cons:

  • hardware acceleration is spotty. games are mostly out.
  • hard to charge to download app. however, can charge for access.

For the people who say that “Well, it doesn’t work on other browsers”. That’s only half true. While this method of removing top and bottom bars only works on iPhone/iPad, the app still functions 100% normally in other mobile browser. Building a mobile app gets you 90% of the way, and adding that ONE LINE gets you the rest of the way for apple browsers.

Here is where you can try it on your ipad (or iphone/ipod touch): http://ablu.us/files/uh_ipad


Gmail and Tips and Tricks

Wednesday, May 5th, 2010

Did you know that you can modify your gmail address with and it will still reach you? Gmail ignores dots ‘.’ and everything after a plus ‘+’ sign.

This comes in extremely handy. Need to create several test accounts on your new web app? No problem! Just move around a dot in your address! Need to give an email address, but don’t want to ever receive email from them? Tack a ‘+spam’ on the end of your address and filter it to automatically be marked read and go to the trash.

Let’s take a look at how to do this.

The Dot

Gmail handily ignores all dots in the name part of your email address. andre.bluehs@gmail.com is exactly the same as andrebluehs@gmail.com is exactly the same as a.n.d.r.e.b.l.u.e.h.s@gmail.com. This is useful for signing up for accounts that require a unique email address, but you already have an account for (for testing, purposes, of course). All emails will go to your account, regardless of where and how many dots are in the name.

This also works for signing in to google. you can use your username without the @gmail part when logging into gmail. (This is not true for third party apps using your gmail identity for log in, such as stackoverflow, you need to provide your full email address)

The Plus

This hack is extremely useful for ‘tagging’ email from certain places. If a site requires that you give an email address, simply put a +spam at the end of your username, and filter it. Note: you can put whatever you want after the +, i just use ‘spam’ here as an example. Gmail does not automatically filter things with ‘+spam’ on the end, you must do this manually with the next step.

To create the appropriate filter, click on ‘create new filter’ next to the search button:

Then put in the To: field, whatever your email address is, with a ‘+spam’ for the username.

and finally, check ‘mark as read’ and ‘delete it’ in the last step.

and you’re done! never to be pestered by ‘affiliate email’ again.

This can be repeated for any kinds of filters you want, as well as using the dot hack with this filtering hack to accomplish the same thing.