lib/oversip/launcher.rb in oversip-1.0.4 vs lib/oversip/launcher.rb in oversip-1.0.5

- old
+ new

@@ -296,10 +296,20 @@ # Create PID file. create_pid_file(options[:pid_file]) log_system_info "reactor running" + + # Run the user provided on_started callback. + log_system_info "calling user provided OverSIP::SystemEvents.on_started() callback..." + begin + ::OverSIP::SystemEvents.on_started + rescue ::Exception => e + log_system_crit "error calling user provided OverSIP::SystemEvents.on_started() callback:" + fatal e + end + log_system_info "master process (PID #{$$}) ready" log_system_info "#{::OverSIP::PROGRAM_NAME} #{::OverSIP::VERSION} running in background" # Write "ok" into the ready_pipe so grandparent process (launcher) # exits with status 0. @@ -311,13 +321,14 @@ # Stop writting into standard output/error. $stdout.reopen("/dev/null") $stderr.reopen("/dev/null") ::OverSIP.daemonized = true - + # So update the logger to write to syslog. ::OverSIP::Logger.load_methods + # Set the EventMachine error handler. ::EM.error_handler do |e| log_system_error "error raised during event loop and rescued by EM.error_handler:" log_system_error e end @@ -425,25 +436,26 @@ ::OverSIP::Config.reload_logic end # Signal CHLD is sent by syslogger process if it dies. trap :CHLD do - # TODO: This won't be logged since syslogger process has died! + # NOTE: This won't be logged if the died proces is oversip_syslogger! log_system_crit "CHLD signal received, syslogger process could be death" end end + def self.terminate error=false unless error log_system_info "exiting, thank you for tasting #{::OverSIP::PROGRAM_NAME}" end # Kill Stud processes. kill_stud_processes # Wait a bit so pending log messages in the Posix MQ can be queued. - sleep 0.05 + sleep 0.1 delete_pid_file ::OverSIP::Logger.close # Fill the syslogger process. kill_syslogger_process @@ -500,11 +512,11 @@ bin_dir = ::File.join(::File.absolute_path(::File.dirname(__FILE__)), "../../bin/") stdout_file = "/tmp/stud.#{listen_ip}:#{listen_port}.out" ::Dir.chdir(bin_dir) do - pid = POSIX::Spawn.spawn "./oversip_stud #{stud_user_group} #{ssl_option} -f '#{listen_ip},#{listen_port}' -b '#{bg_ip},#{bg_port}' -n 2 -s --daemon --write-proxy #{::OverSIP.configuration[:tls][:full_cert]}", :out => stdout_file, :err => "/dev/null" + pid = ::POSIX::Spawn.spawn "./oversip_stud #{stud_user_group} #{ssl_option} -f '#{listen_ip},#{listen_port}' -b '#{bg_ip},#{bg_port}' -n 2 -s --daemon --write-proxy #{::OverSIP.configuration[:tls][:full_cert]}", :out => stdout_file, :err => "/dev/null" Process.waitpid(pid) end # Get the PID of the daemonized stud process. stdout = ::File.read stdout_file @@ -529,9 +541,10 @@ end def self.kill_stud_processes return false unless ::OverSIP.master_pid + return false unless ::OverSIP.stud_pids ::OverSIP.stud_pids.each do |pid| begin log_system_info "killing stud server with PID #{pid}..." ::Process.kill(:TERM, pid)