module Raemon::Server

Public Instance Methods

boot!() click to toggle source

Initializes application components without starting the master process

# File lib/raemon/server.rb, line 7
def boot!
  load_environment
  load_lib # Must be second so that initializers have access to lib
  load_initializers
end
pid_file() click to toggle source

@return [Pathname] the target PID file

# File lib/raemon/server.rb, line 26
def pid_file
  config.root.join("tmp/pids/#{server_name_key}.pid")
end
shutdown!() click to toggle source

Stop the master daemon

# File lib/raemon/server.rb, line 21
def shutdown!
  stop_master_daemon
end
startup!() click to toggle source

Start the master daemon. Exits the script if the master daemon is already running.

# File lib/raemon/server.rb, line 15
def startup!
  stop_if_running!
  start_master_daemon
end

Private Instance Methods

config() click to toggle source
# File lib/raemon/server.rb, line 78
def config
  Raemon::Configuration
end
load_environment() click to toggle source
# File lib/raemon/server.rb, line 62
def load_environment
  environment_file = config.root.join("config/environments/#{config.env}.rb")
  eval File.read(environment_file), binding
end
load_folder(path) click to toggle source
# File lib/raemon/server.rb, line 82
def load_folder(path)
  Dir["#{path}/*.rb"].each { |file| require(file) }
end
load_initializers() click to toggle source
# File lib/raemon/server.rb, line 67
def load_initializers
  load_folder(config.root.join("config/initializers"))
end
load_lib() click to toggle source
# File lib/raemon/server.rb, line 71
def load_lib
  libdir = config.root.join("lib")

  $LOAD_PATH.unshift libdir
  load_folder libdir
end
running?() click to toggle source
# File lib/raemon/server.rb, line 32
def running?
  pid = File.read(pid_file).to_i rescue 0
  Process.kill(0, pid) if pid > 0
rescue Errno::ESRCH
end
server_name_key() click to toggle source
# File lib/raemon/server.rb, line 86
def server_name_key
  config.server_name.downcase.gsub(' ', '_')
end
start_master_daemon() click to toggle source
# File lib/raemon/server.rb, line 45
def start_master_daemon
  config.logger.info "=> Booting #{config.server_name} (#{config.env})"

  Raemon::Master.start(config.num_workers, worker_class, {
    :name         => config.server_name,
    :pid_file     => pid_file,
    :detach       => config.detach,
    :logger       => config.logger,
    :timeout      => config.timeout,
    :memory_limit => config.memory_limit
  })
end
stop_if_running!() click to toggle source
# File lib/raemon/server.rb, line 38
def stop_if_running!
  if running?
    config.logger.error "Error: #{config.server_name} is already running."
    exit
  end
end
stop_master_daemon() click to toggle source
# File lib/raemon/server.rb, line 58
def stop_master_daemon
  Raemon::Master.stop(:pid_file => pid_file)
end
worker_class() click to toggle source
# File lib/raemon/server.rb, line 90
def worker_class
  instance_eval(config.worker_class)
end