Monday, November 25, 2013

Deploy Rails application from Github to AWS EC2 using Capistrano 3


Prerequisites


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/developer_to_be_added_id_rsa.pub | ssh @ "cat >> ~/.ssh/authorized_keys"
  • Developer public key can be downloaded from github curl -O https://github.com/.keys

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/id_rsa.pub | 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

    #####deploy.rb#######

    set :application, 'app name'
    set :repo_url, 'git@github.com:/.git'
    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"
            end
          end
        end
      end

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

      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
          Rake::Task["deploy:stop"].invoke
          Rake::Task["deploy:start"].invoke
        end  
      end

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

      after :finishing, 'deploy:cleanup'

    end

    #####staging.rb#######

    set :stage, :staging

    server 'ec2-hostname.amazonaws.com', 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‘
    ALEX JUNIOR SYRUP 60
    RODIL 8 SYP
    FANORH SYRUP GOML
    SXLERR NASRL DROP
    DCIUGDCU LOTION SOH
    Other things that failed miserably

    www.onlineocr.net/

    www.free-ocr.com/


    http://www.ocr-extract.com/


    http://www.i2ocr.com/


    Friday, November 2, 2012

    A better search engine implementation

    Got this thought while sharing a bookmark with my friends. A better search engine is one that searches (shared) bookmarks of every person. It is a curated content waiting to be indexed and used.

    Maybe i will write a chrome plugin for this.

    Arduino in Bangalore


    The below reference is a good doc on where to buy Arduino in Bangalore

    http://sudarmuthu.com/blog/buying-arduino-in-bangalore



    You can also buy at OM Technology center in SP Road, when i went for buying there, i only got a clone of Uno as they ran out of stock. The clone costed 700.




    OM Technology Centre is opp to Luciya Hotel, OTC Road.




    The clone had “Freeduino USB 1.1″ printed in it and i had a tough time finding what to choose in Arduino IDE to load it. Finally by mistake i choose Arduino Uno and it gulped the code. All over the net, Freeduino USB 1.1 mapped to Diecimilia.

    This is the best documentation on step by step guide on how to install CP2102 driver and get the freeduino board working

    http://probots.co.in/Manuals/Probots%20Freeduino%20USB%201.0%20-%20Starter%20Guide.pdf

    i tried in Mac 10.7 and it didnt work, then switched to my Windows 7 bx and was able to load the program.