Monday, November 25, 2013

Deploy Rails application from Github to AWS EC2 using Capistrano 3


1. EC2 Instance
2. GitHub account with some code
3. Confirm SSH has been enabled on this instance
4. Connecting to a EC2 Instance

How to grant access to multiple developers to EC2 instance

  • Ask a developer who already has access to the machine to add your public key to authorized keyscat ~/somefolder/ | ssh @ "cat >> ~/.ssh/authorized_keys"
  • Developer public key can be downloaded from github curl -O

Setup (for a new instance)

  • Use Amazon Linux AMI 2013.09.1 - Amazon Machine Image (AMI) - 64 bit
  • Open SSH and TCP Ports (while setting up instance, or it can be done later too)
  • Add your public key to authorized keys so that you don't have to use the private key each timecat ~/.ssh/ | ssh -i ec2-user@ "cat >> ~/.ssh/authorized_keys"
  • Install Ruby 2.0 and Rails 4.0 - make sure Ruby is installed with openssl, donot install rvm and ruby as root user
  • Confirm Ruby has been installed with OpenSSL ruby -ropenssl -e "puts OpenSSL::VERSION"
  • Configure SSH Agent forwarding for capistrano - Agent forwarding should work out of the box, just make sure to add your keys to the agent using ssh-add
    1. Verify that git connection using ssh-agent is working cap staging git:check
    2. Troubleshooting
  • Provision server to deploy servers list using capistrano
    1. Edit staging.rb/production.rb and change/add new machine
    2. Create folder with its role in home dir $mkdir staging or mkdir production 
  • Deploy to staging cap staging deploy

  • Capistrano Deploy Scripts


    set :application, 'app name'
    set :repo_url, ''
    set :rvm_type, :user

    namespace :deploy do

      desc "Start unicorn"
      task :start do
        on roles(:app), in: :sequence, wait: 5 do
          within current_path do
            with rails_env: fetch(:stage) do
              execute :bundle, "exec unicorn_rails -c config/unicorn.rb -D"

      desc "Stop unicorn"
      task :stop do
        on roles(:app), in: :sequence, wait: 5 do
          execute "kill -s QUIT `cat #{shared_path}/`" if test("[ -f #{shared_path}/ ]")

      desc 'Restart unicorn'
      task :restart do
        on roles(:app), in: :sequence, wait: 5 do
          # this is a bad way to invoking, but spent 3 hrs searching for this

      before 'deploy:start', 'rvm:hook'

      after :finishing, 'deploy:cleanup'



    set :stage, :staging

    server '', user: 'ec2-user', roles: %w{app}

    set :branch, 'develop'

    set :deploy_to, '/home/ec2-user/staging'

    Tuesday, April 9, 2013

    Best Mobile phone in India for People with Hearing Loss

    My dad has hearing loss and hence needed a phone that

    1) works with his hearing aid, so that there is no interference between phone and the hearing aid, both being electronic devices

    2) Has a good voice clarity while hearing

    3) is less than 10k INR

    we went to Univercell mobile store  in Indiranagar, Bangalore, where a young chap helped us to try various mobile phones with my dad to check for hearing quality.

    We narrowed down to three models,  Nokia,  Samsung and Sony.

    Finally after all tests, we narrowed down to Sony Xperia Tipo, it has Android ICS and had good voice quality while hearing. Now i don't have to shout over the phone to talk to my dad, it is like talking to other ppl over phone and he is able to respond to me over the phone.

    Price (as of Apr 10th): 9000 INR

    the other models that we tried.

    Samsung Galaxy Y Duos (better than Nokia, but Android version was 2.3 and voice clarity was not as good as Sony)
    Nokia Asha (bad compared to both Samsung and the winner).

    Thursday, March 14, 2013

    Alternative(s) to Google Reader

    As a Google Reader user, you must have by now seen the message from google about Reader being decommissioned. Google Reader was an average tool, a dumb one that just collates all my news subscriptions. 

    Folks at Feedly should have been having a blast and partying all night. Though Reader was not a big competitor for them, it would have been a pain in the ass, loosing sleep over the thought that Google might release a better version tomorrow.

    I will not be giving Top 5 or 10 suggestions on what are the alternatives for Google Reader. Afaik, Feedly is the way to go. Feedly can import all your Google Reader feeds, so no worries about copy pasting all links.

    And, yes now there is a blog post from Feedly on steps to migrate.

    If you have an iPad, then Feedly app for iPad is must have.

    For folks who aren't convinced that one alternative is not an alternative. Here are 7 other alternatives to Google Reader (the original article is about 8, expect 7 since we have already covered feedly).

    Wednesday, March 6, 2013

    Best Online OCR Tool for Dot Matrix

    The best online OCR tool based on trying out the below tools is NewOCR

    It lets you upload an image, rotate it (optional), select the region that you want to run OCR and displays the results below, all this in a jiffy.

    I tried the below online links, but some didn't even recognize that the image had text in it.

    Output from NewOCR

    OTRINOZ BABY 0.1325‘
    Other things that failed miserably