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.


Prerequisites


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




End


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.

Wednesday, January 21, 2009

theme_support and formatted routes (rss feeds)

Today I was trying to get my web app to allow subdomains to provide an rss feed. it didn't work.



I'll be posting a solution when one is found, however, i'm hoping this wasn't pebkac again.



Solution


In your controller, where you are making the rss call, you must render layout false. Here is an example:

format.rss { render :layout => false }
I'll file this one under the learn something new, that is easy, everyday column.


After some investigation, it appears that theme_support plugin doesn't support themed rss feeds, when you enter them in the head section of an html page. I'm working to allow this in the plugin.

Saturday, January 10, 2009

passenger and the case of the non-redirecting account. -solved cause i'm dumb.......

Let me explain what is going on here. In my code I want the user to create an account (from www.domain.com) and then, upon successful creation of the account, I want them to redirect to the new account's url, at say account.domain.com.


Redirect doesn't happen in Production


I'm using Passenger and Apache on a ubuntu server.


On my dev box: Mongrel from the rails app, the usual script/server stuff


So on dev, it works fine. I get redirect with reckless abandon.

In production, a different story. I get the following error (using safari, yet to try with other browsers...).Safari can’t connect to the server.
Safari can’t open the page “http://www.example69.com/accounts” because it could not connect to the server “www.example69.com”.

Why me? I should say, I can type my new url into the browser, no problem. it works fine, but it's not what I want my user's to have to do.


Did you solve this?


Embarrassingly I had a link to localhost:3000 as my redirect. Ignore this post. it's left as a reminder when i get too fucking cocky.... as a mark on my pride.