Class: DaemonKit::Configuration
- Inherits:
-
Object
- Object
- DaemonKit::Configuration
- Includes:
- Configurable
- Defined in:
- lib/daemon_kit/initializer.rb
Overview
Holds our various configuration values
Instance Attribute Summary collapse
-
#instance ⇒ Object
Process instance number, defaults to 1.
-
#load_paths ⇒ Object
List of load paths.
-
#log_level ⇒ Object
The log level to use, defaults to DEBUG.
-
#log_stdout ⇒ Object
Duplicate log data to stdout.
-
#logger ⇒ Object
Custom logger instance to use.
- #pid_file(instance = instance) ⇒ Object
-
#root_path ⇒ Object
readonly
Root to the daemon.
-
#shutdown_hooks ⇒ Object
readonly
:nodoc: Shutdown hooks.
-
#signal_traps ⇒ Object
readonly
Collection of signal traps.
Instance Method Summary collapse
-
#at_shutdown(proc = nil, &block) ⇒ Object
Add a block or proc to be called during shutdown.
- #daemon_initializer ⇒ Object
- #environment ⇒ Object
-
#environment_path ⇒ Object
The path to the current environment’s file (
development.rb
, etc.). -
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#trap(signal, proc = nil, &block) ⇒ Object
Add a trap for the specified signal, can be code block or a proc.
Methods included from Configurable
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'lib/daemon_kit/initializer.rb', line 283 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 @signal_traps = {} @shutdown_hooks = [] end |
Instance Attribute Details
#instance ⇒ Object
Process instance number, defaults to 1
254 255 256 |
# File 'lib/daemon_kit/initializer.rb', line 254 def instance @instance end |
#load_paths ⇒ Object
List of load paths
239 240 241 |
# File 'lib/daemon_kit/initializer.rb', line 239 def load_paths @load_paths end |
#log_level ⇒ Object
The log level to use, defaults to DEBUG
245 246 247 |
# File 'lib/daemon_kit/initializer.rb', line 245 def log_level @log_level end |
#log_stdout ⇒ Object
Duplicate log data to stdout
251 252 253 |
# File 'lib/daemon_kit/initializer.rb', line 251 def log_stdout @log_stdout end |
#logger ⇒ Object
Custom logger instance to use
242 243 244 |
# File 'lib/daemon_kit/initializer.rb', line 242 def logger @logger end |
#pid_file(instance = instance) ⇒ Object
337 338 339 340 |
# File 'lib/daemon_kit/initializer.rb', line 337 def pid_file( instance = instance ) @pid_file ||= File.join( File.dirname(self.default_log_path), "#{self.daemon_name}.#{instance}.pid" ) end |
#root_path ⇒ Object (readonly)
Root to the daemon
236 237 238 |
# File 'lib/daemon_kit/initializer.rb', line 236 def root_path @root_path end |
#shutdown_hooks ⇒ Object (readonly)
:nodoc: Shutdown hooks
281 282 283 |
# File 'lib/daemon_kit/initializer.rb', line 281 def shutdown_hooks @shutdown_hooks end |
#signal_traps ⇒ Object (readonly)
Collection of signal traps
278 279 280 |
# File 'lib/daemon_kit/initializer.rb', line 278 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
331 332 333 334 335 |
# File 'lib/daemon_kit/initializer.rb', line 331 def at_shutdown( proc = nil, &block ) return if proc.nil? && !block_given? @shutdown_hooks << ( proc || block ) end |
#daemon_initializer ⇒ Object
309 310 311 |
# File 'lib/daemon_kit/initializer.rb', line 309 def daemon_initializer "#{root_path}/config/initializers/#{self.daemon_name}.rb" end |
#environment ⇒ Object
299 300 301 |
# File 'lib/daemon_kit/initializer.rb', line 299 def environment ::DAEMON_ENV end |
#environment_path ⇒ Object
The path to the current environment’s file (development.rb
, etc.). By default the file is at config/environments/#{environment}.rb
.
305 306 307 |
# File 'lib/daemon_kit/initializer.rb', line 305 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
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/daemon_kit/initializer.rb', line 314 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 |