lib/adhearsion/initializer.rb in adhearsion-1.0.3 vs lib/adhearsion/initializer.rb in adhearsion-1.1.0
- old
+ new
@@ -123,11 +123,11 @@
# case one is created. You can force Adhearsion to not create one
# even in daemon mode by supplying "false".
def initialize(path=nil, options={})
@@started = true
@path = path
- @daemon = options[:daemon] || ENV['DAEMON']
+ @mode = options[:mode]
@pid_file = options[:pid_file].nil? ? ENV['PID_FILE'] : options[:pid_file]
@loaded_init_files = options[:loaded_init_files]
self.class.ahn_root = path
end
@@ -135,10 +135,11 @@
Adhearsion.status = :starting
resolve_pid_file_path
resolve_log_file_path
daemonize! if should_daemonize?
+ launch_console if need_console?
switch_to_root_directory
catch_termination_signal
create_pid_file if pid_file
bootstrap_rc
initialize_log_file
@@ -166,11 +167,11 @@
def resolve_pid_file_path
@pid_file = if pid_file.equal?(true) then default_pid_path
elsif pid_file then pid_file
elsif pid_file.equal?(false) then nil
# FIXME @pid_file = @daemon? Assignment or equality? I'm assuming equality.
- else @pid_file = @daemon ? default_pid_path : nil
+ else @pid_file = (@mode == :daemon) ? default_pid_path : nil
end
end
def resolve_log_file_path
@ahn_app_log_directory = AHN_ROOT + '/log'
@@ -313,19 +314,37 @@
Events.framework_theatre.load_events_file file
end
end
def should_daemonize?
- @daemon
+ @mode == :daemon
end
+ def need_console?
+ @mode == :console
+ end
+
def daemonize!
ahn_log "Daemonizing now! Creating #{pid_file}."
extend Adhearsion::CustomDaemonizer
daemonize log_file
end
+ def launch_console
+ require 'adhearsion/console'
+ Thread.new do
+ begin
+ puts "Starting console"
+ Adhearsion::Console.run
+ Adhearsion.shutdown!
+ rescue Exception => e
+ puts e.message
+ puts e.backtrace.join("\n")
+ end
+ end
+ end
+
def initialize_log_file
Dir.mkdir(ahn_app_log_directory) unless File.directory? ahn_app_log_directory
file_logger = Log4r::FileOutputter.new("Main Adhearsion log file", :filename => log_file, :trunc => false)
if should_daemonize?
@@ -380,10 +399,10 @@
index = 0
until index == IMPORTANT_THREADS.size
begin
IMPORTANT_THREADS[index].join
rescue => e
- ahn_log.error "Error after join()ing Thread #{thread.inspect}. #{e.message}"
+ ahn_log.error "Error after join()ing Thread #{Thread.inspect}. #{e.message}"
ensure
index = index + 1
end
end
end