SUPPORT THE SITE WITH A CLICK

Subscribe Rss:

SUPPORT THE SITE WITH A CLICK

Monday, October 1, 2012

Getting started with Unicorn with rails

I have doing deploys with mongrel cluster, phusion passenger and ngnix for over two years now.Later on used to work with thin server for development env.

Now rails 3.2 higher version, by default suggest unicorn as the app server.Also github has moved to unicorn.so decided to go with unicorn.

Getting started

Install the gem unicorn

It’s simple to run Unicorn with a bunch of workers and send it commands just like you would in production.

First, create a basic config/unicorn.rb.
#Unicorn minimal configuration 
worker_processes 2
preload_app true
timeout 30
listen 2007

pid "tmp/pids/unicorn.pid"
stderr_path "log/unicorn.stderr.log"
stdout_path "log/unicorn.stdout.log"

after_fork do |server, worker|
  ActiveRecord::Base.establish_connection
end
Here i go with my minimal configuration as my app was in development mode.
Check the docs, or the official example, or the Github sample.

Now start your Unicorn server with config file as

unicorn_rails -c config/unicorn.rb -D.

Finally our app runs with unicorn server at port 2007