Chronicling my experiences with ruby on rails, web application development/management.

Sunday, January 25, 2009

How to deploy when Capistrano doesn't work for you.

What happens when Capistrano just doesn't work for you?

Ok, maybe i'm the only one with that problem, but i've tried on three different server providers, linode, gogrid and slicehost. All had the same problem, somehow, someway my user privleges were f!@#cking it up.

When a tutorial i've trusted tells me to put my directory to chown www-data, well, i am going to do that. In order to do this i need to sudo everything, thanks to ubuntu, and it's a best practice i can wrap my feeble mind around.

How to deploy a rails app when Capistrano just ain't working for you.

I've not been able to find one source on the net that showed me simply how to deploy a web app using just git, and ssh. So i'm open to better ways, however, i've tested this way for the last 3 weeks and am pretty happy with it.


You are using

  • GIT locally and on your server
  • a full Rails setup (I'm using passanger)
  • a server that hosts both your git repository and your app
  • you've setup both your app and git repository on that server box too

  • You are also using www-data as the group and user who "owns" the app on the server.
    That is just too much shit to talk about right now.

The code below walks you through what to do AFTER your initial setup of your server and app environment.

  • On my laptop:

  • Make the changes to your app, when every test passes and when you are ready to go to production do the following:

    • git status # on my machine changes appear in red.

    • git add . # notice the dot after the add

    • git status # if you see anything in red that should also be included use the second git commit line below

    • git commit -m "Add your message about what your committing here." #most of the time use this

    • git commit -a -m "Added all files including untracked ones" # Again only use this one if there are files that appear in red and should also be included in your commit.

    • git push # pushes your code to your server.

  • SSH to server, all these commands are done from your server:

    • cd /var/your/directory/to/your/app # e.g, /var/www/myapp

    • sudo git pull #pulls all of your latest changes and merges them into your app. see troubleshooting if something f@#cks up.

    • sudo rake db:migrate RAILS_ENV="production" # and any other things you need to do, like start ferret or whatever.

    • cd ../ # back out of this directory

    • sudo chown -R www-data:www-data myapp #notice that we are changing ownership of the whole myapp directory and everything below it. Passanger loves this.

    • cd myapp/

    • sudo touch tmp/restart.txt # how to restart passanger


Well i spent 2 or 3 days easily, 4 - 8 hours at a time trying to make capistrano work. The process above takes 3 minutes. Someone else can do the math, but in order for this way to be less efficient, i'd have to do some 300 commits before i regret not having capistrano. One day i'll need it to deploy to 100 servers or something but for now, i can live with the process above.

1 comment:

  1. Bluehost is ultimately the best hosting company for any hosting plans you might require.