class Uc::Server

Attributes

app_dir[R]
paths[R]
rails_env[R]
use_pid[RW]

Public Class Methods

new(app_dir, rails_env: "production", debug: false) click to toggle source
# File lib/uc/server.rb, line 19
def initialize(app_dir, rails_env: "production", debug: false)
  @app_dir = app_dir
  @rails_env = rails_env
  @debug = debug
end

Public Instance Methods

print_config() click to toggle source
reopen_logs() click to toggle source
# File lib/uc/server.rb, line 87
def reopen_logs
  init_once
  return if not server_status.running?
  Process.kill(:USR1 , server_status.pid)
  puts "reopened logs"
end
restart() click to toggle source
# File lib/uc/server.rb, line 57
def restart
  stop
  start
end
rolling_restart() click to toggle source
# File lib/uc/server.rb, line 62
def rolling_restart
  init_once
  if config[:instances] == 0
    puts "0 instances specified: stopping"
    stop if server_status.running?
    return
  end
  uconfig.generate_once
  if not server_status.running?
    start
    return
  end
  event_stream.expect :fin do
    Process.kill("USR2", server_status.pid)
  end
end
start() click to toggle source
# File lib/uc/server.rb, line 25
def start 
  init_once
  if server_status.running?
    puts server_status
    return
  end
  if config[:instances] == 0
    puts "wont start 0 instances"
    return
  end
  ENV["UNICORN_APP_DIR"] = config[:working_dir]
  event_stream.expect :fin do
    cmd %{unicorn -c #{uconfig.path} -D -E #{rails_env} }, return_output: false,
      error_msg: "error starting unicorn"
  end
end
status() click to toggle source
# File lib/uc/server.rb, line 51
def status
  paths.validate_required
  Dir.chdir app_dir
  puts server_status
end
stop() click to toggle source
# File lib/uc/server.rb, line 42
def stop
  init_once
  if server_status.stopped?
    logger.info "unicorn not running"
    return
  end
  kill(server_status.pid, 30)
end

Private Instance Methods

config() click to toggle source
# File lib/uc/server.rb, line 104
def config
  @config ||= ::Uc::Config.new(app_dir).to_h
end
init() click to toggle source
# File lib/uc/server.rb, line 120
def init
  paths.validate_required
  Dir.chdir app_dir
  lock.acquire
  ::Uc::Logger.event_queue = config[:event_queue]
  event_stream.debug_output = true if @debug
end
init_once() click to toggle source
# File lib/uc/server.rb, line 128
def init_once
  @init_once ||= begin
    init
    true
  end
end
lock() click to toggle source
# File lib/uc/server.rb, line 116
def lock
  @lock ||= ::Uc::Lock.new(app_dir)
end
server_status() click to toggle source
# File lib/uc/server.rb, line 96
def server_status
  @server_status ||= ::Uc::Status.new(unicorn_paths, use_pid: use_pid)
end
uconfig() click to toggle source
# File lib/uc/server.rb, line 112
def uconfig
  @uconfig ||= ::Uc::Unicorn::Config.new(config, unicorn_paths)
end
unicorn_paths() click to toggle source
# File lib/uc/server.rb, line 108
def unicorn_paths
  @unicorn_paths ||= ::Uc::Unicorn::Paths.new(config[:working_dir])
end