Capistrano on Media Temple

I recently moved most of the sites I’m maintaining over to Media Temple’s Grid Server hosting service because I was having no luck getting Rails apps deployed on Dreamhost. I gather that people much brighter than me have gotten Rails apps running on Dreamhost without any difficulties, but I just wasn’t able to get it working myself and was looking to move hosts in any case.

I chose Media Temple in large part because of their focus on Rails Containers and because of the tools they’ve built that make it easy to get up and running. It doesn’t hurt that they’ve got pretty reasonable prices, too.

One of the main things that got me interested in Rails is that its “opinionated” nature starts you off on the right foot. Rails apps have development, testing, and production environments from the start, which makes it very easy to make changes to live apps without worrying about screwing things up. Capistrano makes the deployment part of creating and maintaining Rails apps extremely easy. The only thing is that you’ve got to create a “deployment recipe” for use on your web host’s servers.

Here is the Capistrano Deployment Recipe (deploy.rb) that I put together for Media Temple. If you’ve followed the instructions in the Server Guide for how to prepare your (gs) for Rails hosting, just set the proper passwords and stuff in the first few lines and you should be good to go. Enjoy!

require 'mt-capistrano'

set :site,         "0000"
set :application,  "appname"
set :webpath,      "app.com"
set :domain,       "primarydomain.com"
set :user,         "serveradmin%primarydomain.com"
set :password,     "password"

ssh_options[:username] = 'serveradmin%primarydomain.com'

set :repository, "svn+ssh://#{user}@#{domain}/home/#{site}/data/svn/#{application}/trunk"
set :deploy_to,  "/home/#{site}/containers/rails/#{application}"

set :checkout, "export"

role :web, "#{domain}"
role :app, "#{domain}"
role :db,  "#{domain}", :primary => true

task :after_update_code, :roles => :app do
  put(File.read('config/database.yml'), "#{release_path}/config/database.yml", :mode => 0444)
end

task :restart, :roles => :app do
  run "mtr restart #{application} -u #{user} -p #{password}"
  run "mtr generate_htaccess #{application} -u #{user} -p #{password}"
  migrate
end

I originally posted this code on the Rails Weenie forums, but I thought it might be good to post it here so that it doesn’t get lost. This blog post also provided some serious help when I was setting things up, and I think it’s worth a read as well.

If you’re brand new to Capistrano, you’ll have to first install the gems for “capistrano” and Media Temple’s “mt-capistrano” like you would with any other gem. You’ll also want to have Subversion set up for your code repository. If you don’t have SSH keys set up, I think you can add ssh_options[:password] to the recipe instead.

Advertisement

14 Responses to “Capistrano on Media Temple”


  1. 1 Alastair February 6, 2007 at 2:41 pm

    Hey Trevor,

    Thanks for the recipe! It's a very helpful in setting up Capistrano and deploying Rails on (mt) the 'right' way.

    thanks,

    Alastair

  2. 2 bitbutter April 6, 2007 at 12:03 am

    Thanks for this, very useful!

    I'm trying to get cap deploy working on my mt gs account and I'm having a little difficulty though; the capistrano deploy seems to run successfully until the restart command, when it complains that my application doesn't exist. Checking the directory structure in the rails container it looks like it ought to do as far as i can see (the regular capistrano heirarchy). Any ideas for what i should check?

    " * executing "mtr restart mylittleapp -u serveradmin%s1234.gridserver.com -p 123456"

    servers: ["s1234.gridserver.com"]

    [s1234.gridserver.com] executing command

    ** [out :: s1234.gridserver.com] Error executing command:

    ** [out :: s1234.gridserver.com] Application mylittleapp does not exist."

  3. 3 Trevor April 7, 2007 at 1:48 am

    bitbutter, it sound like you need to make sure you've followed the Media Temple instructions that you can find in the administration panel.

    I'd start by setting up the app without capistrano and make sure it works, then add capistrano to it.

  4. 4 Brian Getting July 30, 2007 at 6:39 am

    I found this to be very helpful, except that I have run into a problem. With Capistrano 2.0, it appears that the "%" sign in the username is causing problems. I can connect to the server and run all the Media Temple (cap mt_add) commands, but when I try to deploy I get an error that says that SSH cannot connect to the repository.

    It looks as though the % sign in the username variable of the deployment recipe is causing problems. Instead, it looks for:

    serveradmin/272lkjdslfaj.com

    where the '/272' appears to be some kind of goof caused by the percent sign. Has anyone had any luck with Media Temple and Capistrano 2.0?

  5. 5 Trevor July 30, 2007 at 7:56 am

    Brian, I actually moved over to Slicehost, so I haven't used Capistrano 2 on Media Temple at all. Sorry!

  6. 6 Akhil Bansal November 12, 2007 at 6:28 pm

    Hi,

    Is there any official documentation for deploying rails application using capistrano on media temple grid servers

  7. 7 Trevor November 13, 2007 at 1:23 am

    I believe there's some documentation in the MT knowledge base, but maybe not. I moved over to Slicehost a few months ago, so I can't say for sure.

  8. 8 James June 1, 2008 at 11:36 pm

    Thanks for the advice.

    I'm not sure, but the recent OS X update (10.5.3) seems to have broken Capistrano with MediaTemple – I fixed this by uninstalling, then re-installing, the capistrano gem.

    More details:

    http://www.sevenoakjournal.co.uk/2008/06/02/os-x-…

    Cheers

  9. 9 Arshad November 1, 2008 at 8:24 pm

    Why did you move to Slicehost? I'm currently on (mt), and am also thinking to move to Slicehost. Just wondering how your experience has been.

  10. 10 Trevor November 2, 2008 at 1:15 pm

    I had some small problems with Media Temple, and I thought the Slicehost pricing/limitation were much more reasonable. At the time I moved, Media Temple would only let me run 1 mongrel, whereas I could run at least 3 with Slicehost for the same cost. I've been really happy with Slicehost, and I wholeheartedly reccomend using them if you're comfortable with server administration (which not everyone is).


  1. 1 Vixiom Axioms » Capistrano deployment recipe for Media Temple Trackback on February 6, 2007 at 7:49 pm
  2. 2 Almost Effortless » Capistrano2 Recipe for Slicehost Trackback on August 4, 2007 at 3:45 pm
  3. 3 Capistrano Trackback on August 24, 2007 at 3:10 pm
  4. 4 Deploying ruby on rails app in Media Temple at Websites You Can Edit Trackback on January 29, 2009 at 4:13 pm
Comments are currently closed.




Follow

Get every new post delivered to your Inbox.