class Unicorn::Wrangler::Main

Attributes

command[R]
grace_period[R]
pidfile[R]
unicorn[RW]

Public Class Methods

new(command, options = {}) click to toggle source
# File lib/unicorn/wrangler.rb, line 145
def initialize(command, options = {})
  @command = command
  @pidfile = File.expand_path(options[:pidfile] || 'unicorn.pid')
  @grace_period = options[:grace_period] || 60
  Wrangler.logger.level = Logger::DEBUG if options[:verbose]
  @unicorn = UnicornProcess.from_pidfile(@pidfile)
end

Public Instance Methods

loop_while_unicorn_runs() click to toggle source
# File lib/unicorn/wrangler.rb, line 184
def loop_while_unicorn_runs
  loop do
    if unicorn.running?
      sleep 0.1
    else
      exit
    end
  end
end
setup_signal_handlers() click to toggle source
# File lib/unicorn/wrangler.rb, line 173
def setup_signal_handlers
  trap_signals(:HUP)  do
    self.unicorn = unicorn.reload(grace_period) if unicorn
  end

  trap_signals(:QUIT, :INT, :TERM) do |signal|
    unicorn.launch_assassin(grace_period) if unicorn
    exit
  end
end
start() click to toggle source
# File lib/unicorn/wrangler.rb, line 153
def start
  $0 = 'unicorn-wrangler (starting up)'
  setup_signal_handlers

  if unicorn && unicorn.running?
    self.unicorn = unicorn.reload(grace_period)
  else
    self.unicorn = UnicornProcess.start(pidfile, command)
    wait_for(grace_period) { unicorn.running? }
  end

  if unicorn.running?
    debug "Unicorn running on #{unicorn.pid}"
    $0 = "unicorn-wrangler (monitoring #{unicorn.pid})"
    loop_while_unicorn_runs
  else
    debug "Unable to start unicorn.  Exiting."
  end
end