Class: DaemonKit::Configuration

Inherits:
Object
  • Object
show all
Includes:
Configurable
Defined in:
lib/daemon_kit/initializer.rb

Overview

Holds our various configuration values

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Configurable

included

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/daemon_kit/initializer.rb', line 296

def initialize
  parse_arguments!

  set_root_path!
  set_daemon_defaults!

  self.load_paths = default_load_paths
  self.log_level  ||= default_log_level
  self.log_path   ||= default_log_path

  self.force_kill_wait = false

  self.safety_net = DaemonKit::Safety.instance

  @signal_traps = {}
  @shutdown_hooks = []
end

Instance Attribute Details

#load_pathsObject

List of load paths



252
253
254
# File 'lib/daemon_kit/initializer.rb', line 252

def load_paths
  @load_paths
end

#log_levelObject

The log level to use, defaults to DEBUG



258
259
260
# File 'lib/daemon_kit/initializer.rb', line 258

def log_level
  @log_level
end

#log_stdoutObject

Duplicate log data to stdout



264
265
266
# File 'lib/daemon_kit/initializer.rb', line 264

def log_stdout
  @log_stdout
end

#loggerObject

Custom logger instance to use



255
256
257
# File 'lib/daemon_kit/initializer.rb', line 255

def logger
  @logger
end

#pid_fileObject

Path to the pid file, defaults to ‘log/<daemon_name>.pid’



267
268
269
# File 'lib/daemon_kit/initializer.rb', line 267

def pid_file
  @pid_file
end

#root_pathObject (readonly)

Root to the daemon



249
250
251
# File 'lib/daemon_kit/initializer.rb', line 249

def root_path
  @root_path
end

#safety_netObject

Our safety net (#Safety) instance



291
292
293
# File 'lib/daemon_kit/initializer.rb', line 291

def safety_net
  @safety_net
end

#shutdown_hooksObject (readonly)

:nodoc: Shutdown hooks



294
295
296
# File 'lib/daemon_kit/initializer.rb', line 294

def shutdown_hooks
  @shutdown_hooks
end

#signal_trapsObject (readonly)

Collection of signal traps



288
289
290
# File 'lib/daemon_kit/initializer.rb', line 288

def signal_traps
  @signal_traps
end

Instance Method Details

#at_shutdown(proc = nil, &block) ⇒ Object

Add a block or proc to be called during shutdown



346
347
348
349
350
# File 'lib/daemon_kit/initializer.rb', line 346

def at_shutdown( proc = nil, &block )
  return if proc.nil? && !block_given?

  @shutdown_hooks << ( proc || block )
end

#daemon_initializerObject



324
325
326
# File 'lib/daemon_kit/initializer.rb', line 324

def daemon_initializer
  "#{root_path}/config/initializers/#{self.daemon_name}.rb"
end

#environmentObject



314
315
316
# File 'lib/daemon_kit/initializer.rb', line 314

def environment
  ::DAEMON_ENV
end

#environment_pathObject

The path to the current environment’s file (development.rb, etc.). By default the file is at config/environments/#{environment}.rb.



320
321
322
# File 'lib/daemon_kit/initializer.rb', line 320

def environment_path
  "#{root_path}/config/environments/#{environment}.rb"
end

#trap(signal, proc = nil, &block) ⇒ Object

Add a trap for the specified signal, can be code block or a proc



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/daemon_kit/initializer.rb', line 329

def trap( signal, proc = nil, &block )
  return if proc.nil? && !block_given?

  # One step towards running on windows, not enough though
  unless Signal.list.include?( signal )
    DaemonKit.logger.warn( "Trapping #{signal} signals not supported on this platform" )
    return
  end

  unless @signal_traps.has_key?( signal )
    set_trap( signal )
  end

  @signal_traps[signal].unshift( proc || block )
end