In Files

Parent

Included Modules

Unicorn::HttpServer

This is the process manager of Unicorn. This manages worker processes which in turn handle the I/O and application process. Listener sockets are started in the master process and shared with forked worker children.

Constants

IO_PURGATORY

prevents IO objects in here from being GC-ed

LISTENERS

all bound listener sockets

WORKERS

This hash maps PIDs to Workers

SELF_PIPE

We use SELF_PIPE differently in the master and worker processes:

  • The master process never closes or reinitializes this once

initialized. Signal handlers in the master process will write to it to wake up the master from IO.select in exactly the same manner djb describes in cr.yp.to/docs/selfpipe.html

  • The workers immediately close the pipe they inherit from the

master and replace it with a new pipe after forking. This new pipe is also used to wakeup from IO.select from inside (worker) signal handlers. However, workers close the pipe descriptors in the signal handlers to raise EBADF in IO.select instead of writing like we do in the master. We cannot easily use the reader set for IO.select because LISTENERS is already that set, and it’s extra work (and cycles) to distinguish the pipe FD from the reader set once IO.select returns. So we’re lazy and just close the pipe when a (rare) signal arrives in the worker and reinitialize the pipe later.

SIG_QUEUE

signal queue used for self-piping

REQUEST

constant lookups are faster and we’re single-threaded/non-reentrant

START_CTX

We populate this at startup so we can figure out how to reexecute and upgrade the currently running instance of Unicorn This Hash is considered a stable interface and changing its contents will allow you to switch between different installations of Unicorn or even different installations of the same applications without downtime. Keys of this constant Hash are described as follows:

  • 0 - the path to the unicorn/unicorn_rails executable
  • :argv - a deep copy of the ARGV array the executable originally saw
  • :cwd - the working directory of the application, this is where

you originally started Unicorn.

The following example may be used in your Unicorn config file to change your working directory during a config reload (HUP) without upgrading or restarting:

  Dir.chdir(Unicorn::HttpServer::START_CTX[:cwd] = path)

To change your unicorn executable to a different path without downtime, you can set the following in your Unicorn config file, HUP and then continue with the traditional USR2 + QUIT upgrade steps:

  Unicorn::HttpServer::START_CTX[0] = "/home/bofh/1.9.2/bin/unicorn"

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.