What is Unicorn for Rails?

Basics

Unicorn is a “Rack HTTP server for fast clients and Unix”

Rack is a gem that acts as an interface for ruby applications to response to web requests. The application itself returns three elements in an array

[HTTP response code, hash of headers, response body]

It’s a fast client, i.e. interacts with Rack quickly but cannot standalone as a server. It requires Nginx or Apache to:

1. Buffer; and 2. Queue web requests

Unicorn Config
Config files requires to know a few things:

  • app_path
  • worker_processes count (= number of cores on server)
  • A listen path (usually to a unicorn.socket)
  • process_id (pid)
  • stderr and stdout logs

Unicorn Init Script
Set up the init script in the:

/etc/init.d/unicorn

File location, allowing it to be launched as a unix service