lib/adhearsion/initializer.rb in adhearsion-2.0.0.alpha2 vs lib/adhearsion/initializer.rb in adhearsion-2.0.0.alpha3
- old
+ new
@@ -2,20 +2,18 @@
require 'adhearsion/linux_proc_name'
module Adhearsion
class Initializer
- extend ActiveSupport::Autoload
-
- autoload :Logging
-
class << self
def start(*args, &block)
new(*args, &block).start
end
end
+ DEFAULT_PID_FILE_NAME = 'adhearsion.pid'
+
attr_reader :path, :daemon, :pid_file
# Creation of pid_files
#
# - You may want to have Adhearsion create a process identification
@@ -45,51 +43,52 @@
start_logging
launch_console if need_console?
catch_termination_signal
create_pid_file
set_ahn_proc_name
- logger.info "Loaded config in <#{Adhearsion.config.platform.environment}> environment"
initialize_exception_logger
update_rails_env_var
init_plugins
- logger.info "Adhearsion v#{Adhearsion::VERSION} initialized!"
- Adhearsion::Process.booted
-
run_plugins
trigger_after_initialized_hooks
+ if Adhearsion.status == :booting
+ Adhearsion::Process.booted
+ logger.info "Adhearsion v#{Adhearsion::VERSION} initialized with environment <#{Adhearsion.config.platform.environment}>!"
+ end
+
# This method will block until all important threads have finished.
# When it does, the process will exit.
join_important_threads
self
end
def update_rails_env_var
env = ENV['AHN_ENV']
if env && Adhearsion.config.valid_environment?(env.to_sym)
- if ENV['RAILS_ENV'] == env
- logger.info "Using the configured value for RAILS_ENV : <#{env}>"
+ if ENV['RAILS_ENV']
+ logger.info "Using provided RAILS_ENV value of <#{ENV['RAILS_ENV']}>"
else
- logger.warn "Updating AHN_RAILS variable to <#{env}>"
+ logger.warn "Setting RAILS_ENV variable to <#{env}>"
ENV['RAILS_ENV'] = env
end
else
env = ENV['RAILS_ENV']
if env
logger.info "Using the configured value for RAILS_ENV : <#{env}>"
else
env = Adhearsion.config.platform.environment.to_s
- logger.info "Defining AHN_RAILS variable to <#{env}>"
+ logger.info "Defining RAILS_ENV variable to <#{env}>"
ENV['RAILS_ENV'] = env
end
end
env
end
def default_pid_path
- File.join Adhearsion.config.root, 'adhearsion.pid'
+ File.join Adhearsion.config.root, DEFAULT_PID_FILE_NAME
end
def resolve_pid_file_path
@pid_file = if pid_file.equal?(true)
default_pid_path
@@ -172,18 +171,11 @@
end
if should_daemonize?
appenders
else
- stdout = ::Logging.appenders.stdout(
- 'stdout',
- :layout => ::Logging.layouts.pattern(
- :pattern => Adhearsion::Logging.adhearsion_pattern,
- :color_scheme => 'bright'
- )
- )
- appenders << stdout
+ appenders += Adhearsion::Logging.default_appenders
end
end
def init_plugins
Plugin.init_plugins
@@ -236,10 +228,10 @@
end
end
def start_logging
outputters = init_get_logging_appenders
- Logging.start outputters, Adhearsion.config.platform.logging.level, Adhearsion.config.platform.logging.formatter
+ Adhearsion::Logging.start outputters, Adhearsion.config.platform.logging.level, Adhearsion.config.platform.logging.formatter
end
def initialize_exception_logger
Events.register_handler :exception do |e|
logger.error e