Setting up a Rails app on a Media temple grid server

Now that I’m back from Sydney, I have had a bit more of a change to play with my shiny new MediaTemple grid server account. It looks like I will be pushing 88 Miles over to it over the weekend - everything is setup and ready to go, and just have to do the migrating. I though I would share with you a few thinks I found out along the way…

Setting up the Rails environment

The instructions on the media temple site are pretty good, there are just a few caveats I would make. Firstly, I’ve now started using capistrano to deployment, so I decided to change a few of the directory structures away from how MT suggests. The steps I took are as follows changes from the MT instructions are emphasised (replace testapp with you apps name - obviously):

cd $HOME/../../containers
mkdir rails && cd rails
mkdir testapp && cd testapp
mtr add testapp $PWD/current

For those of you playing at home, you may have noticed that the /current directory, doesn’t yet exist. Correct! This will get created by capistrano.

Setting up Capistrano

Everything was pretty straight forward in the deploy.rb file. The only gotchas I cam across were specific to my installation:

If your svn repository has a space in it, wrap it in single quotes when assigning the :repository variable, i.e:

  1. set :repository, “’svn://svn.server.com/path/to/your repository’”

If your svn repository requires a username and password for checkout or export, use the :svn_username variable, i.e:

  1. set :svn_username,
  2. Proc.new { “username –password password” }

The only other modification I needed to make to the deploy file was the addition of the restart task. Because MT uses custom scripts to restart containers, the restart script needs to call them reather than trying to mess with the Apache or Mongrel processes. I also discovered that my secure certificate wasn’t functioning correctly (I’ll explain why in a second) so there is a fix for that here as well.

  1. desc “Restart the rails container”
  2. task :restart, :roles => :app do
  3. run “mtr generate_htaccess test_app”
  4. run “echo ‘RequestHeader set X_FORWARDED_PROTO \”https\” env=HTTPS’ >> #{deploy_to}/current/public/.htaccess”
  5. run “mtr create_link test_app”
  6. run “mtr restart test_app”
  7. end

Line 3 uses a MT script to make some modifications to the apps .htaccess file. Because Mt proxies all requests to the apps Mongrel server, the standard .htaccess doesn’t cut the mustard.

Line 4 makes another modification to the .htaccess file. Because I’m slack, I pull a neat trick when I do SSL. I maintain a global list of pages that require SSL - when a user browsers to that page, they automatically get redirected to the secure version if required. And the same works the other way - if they browser away from a secure page to a non-secure page, they get re-directed to the non-secure version. Unfortunately, because of the way MT proxies the request, the Mongrel server knows nothing about whether the connection is secure of not (i.e request.ssl? always returns false). Thankfully, there is a fix for this in Rails - if you include the X_FORWARDED_PROTO=https header in the request, rails knows what is going on. This line checks for the environmental variable HTTPS (Which is a flag that is set if the server is in SSL mode) and if it is, sends the modified header, which makes everything good again.

Line 5 links the web directory to the rails container and line6 restarts the server. Nice and easy!

MediaTemple’s new grid server services

What can you get for $20 per month these days? A Basecamp account? 4 88 Miles accounts? An account of a Grid server with 100Gb of disk space, 100Tb of traffic with support for upto 100 sites? Yeah. Media Temple has just released an insamely priced grid server setup that offers all of that FOR $20 PER MONTH. They even support Ruby on Rails using containers and mongrel. Needless to say, I signed up for account. hopefully it will come through before I leave for Sydney tomorrow afternoon, otherwise I’ll have to wait a week to play.

What is a grid server?

A grid server is basically lots of little servers that acts like one big server. This means that if a server becomes loaded, they can through more hardware at the problem. Google and Amazon use similar systems, infact Amazon offers a service where you can upload a virtual linux machine on to their grid.

If they pull this off, it will pretty much revolutionise server hosting. I’ll keep you posted how I go with my 88 Miles migration.

The Eftos web tradition lives on…

And what a rich, long living and all-encompassing tradition it is. Ok, there is actually only two of us, and I’m the one that has been in the web biz for the longest, but I’m sure that there may or may not be more to follow in our footsteps. And no, I haven’t gone nuts and started speaking in the third person again - the additional body that makes up the other half of “our” is my little brother, Cyrus, who just released his new and improved portfolio and blog site.

He obviously has a designer bent, which is cool because it means he might be useful to me some day :)

Seriously though, I quite like the look. So a big “Nice” goes out to him. Check it.

Who could have thought an umlet could be so funny…

I was just catching up on the tawdry adventures of workmate Simon’s trip around Europe. Possibly one of the funniest travel blogs I’ve read (Also probably the ONLY travel blog I’ve read, but if I’d read more, I reckon it would still be up there) and I got a flash back to a couple of weeks ago when he popped up on MSN.

He was in the middle of Sweden and we were basking in the light of umlets and agraves (As we do - Simon is a typography enthusist and I just love the sound of the word umlut). Of course funky inflections on characters is almost exclusively an Ikea thing over here in Australia, our alphabet isn’t blessed with anything more interesting than an X. So, anytime I see a swedish word, I immediately think flat-pack furniture, and so our new swedish car game was borne

Happy birthday Bloggy Hell!

Wow. I’ve been blogging for 12 months today. Crazy. So as a birthday present to my blog, I decided to give it a nice coat of (pixilated) paint. Still needs a little work, but it definately an improvement :)
Thankyou to those that still read this thing. I’ll send you all a virtual hug.

« Previous Entries