1. Capistrano deployment for Rails

    I think I have found my all time favorite gem; capistrano-unicorn Simply put, if you use Capistrano and Unicorn, you have to use this gem.  I have messed around with setting up init.d scripts for starting and stopping Unicorn and they have all been more trouble than help. All I had to do was add a couple of lines to my deploy.rb file:

    # Unicorn tasks
    require 'capistrano-unicorn'
    after 'deploy:restart', 'unicorn:reload'
    after 'deploy:restart', 'unicorn:restart'
    I think that the best thing about this gem is the added cap tasks that can be run from your machine:
    cap unicorn:add_worker               # Add a new worker
    cap unicorn:remove_worker            # Remove amount of workers
    cap unicorn:reload                   # Reload Unicorn
    cap unicorn:restart                  # Restart Unicorn
    cap unicorn:show_vars                # Debug Unicorn variables
    cap unicorn:shutdown                 # Immediately shutdown Unicorn
    cap unicorn:start                    # Start Unicorn master process
    cap unicorn:stop                     # Stop Unicorn


  2. Ubuntu 12.04 Rails, Nginx, Unicorn and Capistrano ('2.15.5') Server Setup

    Check out the gist
    
    
    Ubuntu Precise Rails, Nginx, Unicorn and Capistrano ('2.15.5') Server Setup
    =============================
    
    I originally tried to use the ~> 3.0 version of Capistrano, but fell back to the 2.15.5 version.  There were a lot of changes in the new version that I did not feel like learning right at the moment...
    
    ### 1. Setup deploy user
    
    First we will create a new user for deployment:
    
        $  ssh into your server
        $  sudo adduser deploy
    
    Accept the defaults.
    
    Add new user to staff and sudo groups:
    
        $  sudo usermod -a -G staff deploy
        $  sudo usermod -a -G sudo deploy
    
    Switch user:
    
        $  su deploy
        $  cd ~
    
    Update and Install Ubuntu dependencies:
    
        $  sudo apt-get -y update
        $  sudo apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-dev libyaml-dev libcurl4-openssl-dev curl git-core python-software-properties libxslt1-dev libxml2-dev libmysqlclient-dev libsqlite3-dev nodejs imagemagick graphicsmagick-libmagick-dev-compat git-core mongodb
    
    To make life easier, lets go ahead and add our ssh keys to the new server so that we do not have to sign in every time.
    
    Add ssh keys:
    
        $  mkdir ~/.ssh (on the server)
        $  cat ~/.ssh/id_rsa.pub | ssh deploy@IPaddress "cat >> ~/.ssh/authorized_keys" (from your machine)
    
    ### From here you should be ssh'ing into the server as the deploy user......
    
    ### 2. Install Ruby and gems's
    
    Now let's install Ruby, and we use a specific version for the may_app_name app.
    We need the url to get the source and a directory to build in:
    
        $  wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p374.tar.gz
        $  tar -zxvf ruby-1.9.3-p374.tar.gz
        $  cd ruby-1.9.3-p374
        $  echo "gem: --no-ri --no-rdoc" >> ~/.gemrc
        $  ./configure --prefix=/usr/local
        $  make
        $  sudo make install
        $  sudo gem install bundler
    
    ### 3. Unicorn & Nginx
    
        $  sudo apt-get install nginx
    
    The Nginx configuration is the trickiest part of the set up.  This file needs to go in the config file that was created with the Nginx install:
    
        $  cd /etc/nginx
        $  sudo vim nginx.conf (delete the contents and paste in the code from the Nginx.conf file.  (Attachment A)
    
    You will need to edit the IP address on line 22:
    
        server @IPaddress:8080
    
    The Unicorn configuration consists of the unicorn.rb file in the config directory.
    
    ### 4. Deployment Setup
    
    On the server we need to create a directory for the project:
    
        $  sudo mkdir /var/www
        $  sudo chown deploy:deploy /var/www
    
    We are going to use Capistrano for deployment.  Capistrano is able to deploy to different environments such a Production, Staging, and Development.  Make sure that you have the folloeing in your Gemfile:
    
        gem 'capistrano',  '2.15.5'
        and under group :development
          gem 'capistrano-unicorn', :require => false
    
    Make sure you bundle install after adding these gems.
    
    To install Capistrano:
    
        $ capify .
    
    This creates a config/deploy.rb file
    
    The main Capistrano settings are in the config/deploy.rb file.  Additionally there is also a config/deploy/ directory and within that directory there may should be files for the different environments e.g. production.rb, staging.rb, etc.
    
    It should be noted that there are different environments for Capistrano but these as not the same as the Rails environments that are available on a server.  We currently have both beta and live servers running in 'Production' Rails environment.  Think of the Capistrano envirement as simply the remote name for deployment purposes.
    
    Capistrano will use the file in config/deploy that matches the cap deploy.  For example "cap development deploy", will use the config/deploy/development.rb file.
    
    The way that Capistrano works is that the main settings are in the config/deply.rb file:
    
        my_app_name deploy.rb file:
        set :default_stage, 'development'
        set :stages, %w(production staging development)
        require 'capistrano/ext/multistage'
        require 'bundler/capistrano'
    
        set :application, "may_app_name"
        set :repository,  "git@github.com:my_github/my_app_name.git"
        set :deploy_to, '/var/www/may_app_name'
        set :scm, :git
        set :branch, 'master'
        set :user, 'deploy'
        set :deploy_via, :copy
        set :keep_releases, 5
        set :use_sudo, false
        set :ssh_options, {:forward_agent => true}
    
        after "deploy:restart", "deploy:cleanup"
    
        namespace :deploy do
    
          desc "symlink shared files"
          task :symlink_shared, :roles => :app do
            run "ln -nfs #{shared_path}/system/mongoid.yml #{release_path}/config/mongoid.yml"
            run "ln -nfs #{shared_path}/system/application.yml #{release_path}/config/application.yml"
          end
    
          task :restart, :roles => :app, :except => { :no_release => true } do
            run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
          end
    
        end
        before "deploy:assets:precompile", "deploy:symlink_shared"
    
        # Unicorn
        require 'capistrano-unicorn'
        after 'deploy:restart', 'unicorn:reload'    # app IS NOT preloaded
        after 'deploy:restart', 'unicorn:restart'   # app preloaded
    
    The default_stage is the environment that will be run if not other options are passed to the 'cap deploy' call.  The stages list the 3 possible stages that we can use.  These will then coincide with the files in the config/deploy/ directory.
    
    You will have to create each of these files to update with the new IP address or DNS name.  Here is an example of staging.rb:
    
        server "staging.example.com", :app, :web, :db, primary: true
        set :rails_env, 'staging'
    
    First we need to setup the Capistrano:
    
        $  cap staging deploy:setup (or whatever server you are deploying to)
    
    Next we will copy over a couple of configuration files to the shared directory on the server:
    
        $  scp config/mongoid.yml deploy@IPAddress://var/www/may_app_name/shared/system
        $  scp config/application.yml deploy@IPAddress://var/www/may_app_name/shared/system
    
    If there were no errors, you can now deploy using:
    
        $  cap staging deploy:cold (or whatever server you are deploying to)
    
    For more documentation on Capistrano see: http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html
    
    ### 5. Deployment
    
    After all changes are pushed to the master repository and merged, deployment is as follows:
    
        $  cap staging deploy
        $  cap production deploy
    
    ### Attachment A
    
        worker_processes 1;
        user deploy; # for systems with a "nogroup"
    
        pid /tmp/nginx.pid;
        error_log /var/www/may_app_name/shared/log/nginx.error.log;
    
        events {
          worker_connections 1024; # increase if you have lots of clients
          accept_mutex off; # "on" if nginx worker_processes > 1
        }
    
        http {
          include mime.types;
          default_type application/octet-stream;
          access_log /var/www/may_app_name/shared/log/nginx.access.log combined;
          sendfile on;
          tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
          tcp_nodelay off; # on may be better for some Comet/long-poll stuff
          <!-- types_hash_max_size 2048; -->
    
          upstream app_server {
            server 192.168.6.38:8080;
          }
    
          server {
            client_max_body_size 4G;
            server_name *.example.com;
            keepalive_timeout 600s;
            root /var/www/may_app_name/current/public;
            try_files $uri/index.html $uri.html $uri @app;
    
            location @app {
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header Host $http_host;
              proxy_redirect off;
              proxy_pass http://app_server;
            }
    
            # Rails error pages
            error_page 500 502 503 504 /500.html;
            location = /500.html {
              root /var/www/may_app_name/current/public;
            }
          }
        }


  3. Let go of me SSH Session

    Have you ever been in a SSH session that times out on you? Next time you go to your terminal and you can't type because your ssh session has timed out, all you have to do is: Hit ENTER, then ~, and then . Enter, Tilde, Period …


  4. Dealing with Ruby time

    I saw this code the other day: - tempDate = "#{my_object_date.to_date}"
    - displayDate = tempDate[5,2]
    - displayDate += "/"
    - displayDate += tempDate[8,2]
    - displayDate += "/"
    - displayDate += tempDate[0,4]
    = displayDate The result of this code is MM/DD/YY. What the hell?  I am pretty sure that just about every computer language out there has ways to deal with dates.  For Ruby it is strftime. Check out this awesome tool for dealing with dates and time in Ruby: http://www.foragoodstrftime.com/ And when in doubt, google it!! …


  5. Setting up a Ruby on Rails development environment on Mavericks - dean.io

    Great link for upgrading to Mavericks: http://dean.io/setting-up-a-ruby-on-rails-development-environment-on-mavericks/ I have used this 3 times for installing on Mavericks already!! Can not ever remember the gcc42 part :( Thanks for this !! …


  6. Random thoughts...

    I have not really blogged anything of value lately and that is frustrating. It seems like I never have any time for anything. Since I started working a full time position and keeping a full time client, there are not any extra hours in the week.

    I have been trying to work on my first iPhone app that I created a couple of weekends ago. At work we have an iPhone app that was already created and quite complex to say the least. It has not been too bad getting used to using xCode and Objective C but not easy either. The work app uses dynamic positioning for the labels and inputs so this is a lot harder than setting them in the storyboard. So while I learn how to update the iPhone app at work I thought it smart to write my own app. The layout part was easy but I made a Mortgage Loan calculator and the math behind that is insane. Now, I did not create the app for selling it, it was just a learning experience. As for the calculate loan algorithm, I could not even calculate it with scientific calculator. So fun times.

    RailsCRM seems to be a lingering thing that I will never get around to finishing.  I would maybe be better off trying to figure out how to clone myself.  I have had quite a few visitors to the live site but nobody seems interested in collaborating on it.  One day I will have more time to do something with it.

    I have recently been really focusing on moving to Germany next year.  So I have started to look into companies that are hiring Rails developers there.  Most of the Rails gigs look to be in Berlin where there are so many startups.  There are however, a few other companies in other German cities that are hiring Rails developers.  I have been talking to one such company and it is interesting to hear their work philosophy and how different it is to most of the places that I have talked to or read about here in the states.  Their hiring process is done as a team effort.  The lead developer does the initial interview.  The interview is more about work habits and general coding practices.  If the lead developer feels that you MIGHT be a good fit for the team, the next interview is with the entire team and ultimately the entire team decides yeah or nay on the candidate.  Top priority for them is that the team is made up of those that work well together and that they enjoy working together.  This is more important to them than super ninja coder vs. normal coder.  They do NOT want any hot shot coders that don't fit in with the team.  To me, this is a fantastic philosophy for developers.  It really is more important to be able to mesh and get along great with the other members of your team.  This is not always the case and working in an environment where there is someone that does not get along with others is horrible.  Coding can be improved but changing another's personality is impossible.

      In other news, I recently dropped off of the Social Media circus.  As far as I am concerned, LinkedIn serves no purpose to anybody but recruiters.  People just try to link to as many others as possible, but for what?  Same goes with Twitter.  The more followers the greater you are?  I personally got sick of all of the childish shit that goes on in the RoR community.  Now do not get me wrong, not everybody in the community is bad but most of the chatter on Twitter is nothing more than whining crying and gossip.  It is all about who i going to what conference like a bunch of conference junkies and what goes on there.  I really do not care so I have opted out. …


  7. Why is ruby on rails Ubuntu server setup so damned hard to do?

    Well, I was messing with server setup for Ruby on Rails again.  I had created a script to walk thru the steps but it still seems to be a combination of try this, get an error, google the error, apply the fix, and try it again.  If it works go to next step, and if not; repeat over and over. Now the best option for hosting Rails apps is Heroku but this is not always an option.  A lot of the other 'paid' Rails hosting options have 'one-click' server setup.  What I am talking about is setting up a brand new Ubuntu 12.* server for Ruby on Rails. I will be updating my step-by-step server setup and posting that soon... Today I want to talk about an awesome script that I found.  It is called Railsready by Josh Frye.  Out of the box it certainly kicks ass to use for setting up Rails ready server on 'Nix or OSX. Well, I wanted more, so I added more.  I have taken Josh's fine script and added some options that I wanted. I now have it setup to ask what version Ruby you want installed.  Right now that is a choice of 1.9.3 or 2.0.0.  I am planning on setting that up to prompt for which version but I worry that users will enter a non-existing patch. I have also added Nginx server install plus your choice of Unicorn, Thin or Passenger. Next up is I am going to add option to choose from Mongodb, MySQL, and PostgreSQL. Take a look at it and see what you think...  https://github.com/brobertsaz/railsready


  8. To Saas or not to Saas....

    So I am torn with what to do with RailsCRM.  From the beginning it was always intended to be OSS and minimal.  Then I started to add on to it.  I feel that it should be something easy to use and require minimal setup and not have all of the bells and whistles as those could be added by the user.

    I really do not know if anybody has used it for themselves as I have no idea whether anybody has cloned the repo and done anything with it.

    So, I thought lately that I will set it up as a SaaS and still allow people to clone the basic and advanced crm repos.  But now I am thinking that I should do both.  Maybe make the new version that I have been working on the advanced version as well as setting it up to use as a SaaS.

    I have no intention of making money off of this but I could see that if it were popular as a SaaS that I would incur the costs of running it.

    I know that either way I have a lot of improvements to make and doing that is a little hard with so many other things occupying my time.

    Does anybody think there would be a need for an easy to use CRM SaaS? …


  9. Update from Intern #2 - Transition to Rails

    My second intern, Steve, just posted this on his blog..... "While this post is now a few months late due to life getting in the way, I figured I would document how my first year using Ruby on Rails went. In case you don’t want to read more I would sum it up as a huge success. I picked up my first Ruby on Rails book the end of April 2012......" Check out the full article at http://www.stephentong.com/


  10. New Beginnings....

    Well, lots have changed recently.  As the title says, new beginnings....

    I have had no luck in finding new contracts.  My partner Steve and I are looking at expanding more into the JavaScript market as he worries that Rails is slowly fading away to be replaced by the likes of Node.js and others.

    When one language gets popular, everybody rushes to it.  Have to be the cool hipsters with the new stuff on the block.  That is fine.  As more devs move to the new Javascript single page apps there will be more need for Rails developers on legacy applications.

    So, I have for a while been contemplating getting a real job.  I had hoped to work remotely with somebody but that left me with few options.

    I got an email 2 weeks ago from my blog from a recruiter.  I know, great yet another recruiter email.  The position sounded interesting and I replied to the recruiter.  Long story short, the recruiter, David Claeys with Tech Recruitment, got me an interview with the company and I started last Wednesday.

    I just started working at Unitedweb/Nextiva.  I am the first Rails dev there.  All of the other developers are either Java or Python/Django people.  I am working on a legacy Rails app and I am to teach RoR to others there to work on the app with me.

    One thing that I have to say is that Unitedweb/Nextiva is an awesome place to work.  I was so worried about going back to working in an office for the first time in 5 years.  Needless to say, it does not feel like I am working in an office and for that I am grateful.

    What does this mean for Rebel Outpost?  Business as usual.  I will still continue to look for more contract work.  I still want to be able to teach others and be a big part of the local Ruby community.  So as far as I am concerned there is no end in site... …