Module: Raemon::Server
- Defined in:
- lib/raemon/server.rb
Defined Under Namespace
Classes: Configuration
Class Attribute Summary collapse
-
.config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
- .console! ⇒ Object
- .initialize_application ⇒ Object
- .initialize_logger ⇒ Object
- .load_environment ⇒ Object
- .load_folder(path) ⇒ Object
- .load_initializers ⇒ Object
- .load_lib ⇒ Object
- .pid_file ⇒ Object
- .run {|config| ... } ⇒ Object
- .running? ⇒ Boolean
- .server_name ⇒ Object
- .server_name_key ⇒ Object
- .shutdown! ⇒ Object
- .startup! ⇒ Object
Class Attribute Details
.config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/raemon/server.rb', line 7 def config @config end |
Class Method Details
.console! ⇒ Object
42 43 44 |
# File 'lib/raemon/server.rb', line 42 def console! initialize_application end |
.initialize_application ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/raemon/server.rb', line 46 def initialize_application load_environment load_initializers load_lib initialize_logger end |
.initialize_logger ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/raemon/server.rb', line 54 def initialize_logger return if !config.logger.nil? # Create our own logger if one wasn't provided if config.detach config.logger = Logger.new("#{RAEMON_ROOT}/log/#{server_name_key}.log") else config.logger = Logger.new(STDOUT) end # Set the logger level config.logger.level = instance_eval("Logger::#{config.log_level.to_s.upcase}") # TODO: format the logger # config.logger.formatter end |
.load_environment ⇒ Object
71 72 73 74 |
# File 'lib/raemon/server.rb', line 71 def load_environment environment_file = "#{RAEMON_ROOT}/config/environments/#{RAEMON_ENV}.rb" eval IO.read(environment_file), binding end |
.load_folder(path) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/raemon/server.rb', line 86 def load_folder(path) Dir.entries(path).each do |lib_file| if lib_file != '.' && lib_file != '..' require "#{path}/#{lib_file}" end end end |
.load_initializers ⇒ Object
76 77 78 |
# File 'lib/raemon/server.rb', line 76 def load_initializers load_folder "#{RAEMON_ROOT}/config/initializers" end |
.load_lib ⇒ Object
80 81 82 83 84 |
# File 'lib/raemon/server.rb', line 80 def load_lib libdir = "#{RAEMON_ROOT}/lib" $LOAD_PATH.unshift libdir load_folder libdir end |
.pid_file ⇒ Object
102 103 104 |
# File 'lib/raemon/server.rb', line 102 def pid_file "#{RAEMON_ROOT}/tmp/pids/#{server_name_key}.pid" end |
.run {|config| ... } ⇒ Object
9 10 11 12 |
# File 'lib/raemon/server.rb', line 9 def run @config = Configuration.new if config.nil? yield config if block_given? end |
.running? ⇒ Boolean
106 107 108 109 110 |
# File 'lib/raemon/server.rb', line 106 def running? pid = File.read(pid_file).to_i rescue 0 Process.kill(0, pid) if pid > 0 rescue Errno::ESRCH end |
.server_name ⇒ Object
94 95 96 |
# File 'lib/raemon/server.rb', line 94 def server_name @server_name = config.name || 'Raemon' end |
.server_name_key ⇒ Object
98 99 100 |
# File 'lib/raemon/server.rb', line 98 def server_name_key server_name.downcase.gsub(' ', '_') end |
.shutdown! ⇒ Object
38 39 40 |
# File 'lib/raemon/server.rb', line 38 def shutdown! Raemon::Master.stop :pid_file => pid_file end |
.startup! ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/raemon/server.rb', line 14 def startup! initialize_application # Check if the server is already running if running? $stderr.puts "Error: #{server_name} is already running." exit end # Start the master daemon config.logger.info "=> Booting #{server_name} (#{RAEMON_ENV})" worker_klass = instance_eval(config.worker_klass) Raemon::Master.start config.num_workers, worker_klass, { :name => server_name, :pid_file => pid_file, :detach => config.detach, :logger => config.logger, :timeout => config.timeout, :memory_limit => config.memory_limit } end |