Module: OverSIP::SysLoggerProcess
- Defined in:
- lib/oversip/syslogger_process.rb
Defined Under Namespace
Classes: SysLoggerWatcher
Constant Summary collapse
- SYSLOG_FACILITY_MAPPING =
{ "kern" => Syslog::LOG_KERN, "user" => Syslog::LOG_USER, "daemon" => Syslog::LOG_DAEMON, "local0" => Syslog::LOG_LOCAL0, "local1" => Syslog::LOG_LOCAL1, "local2" => Syslog::LOG_LOCAL2, "local3" => Syslog::LOG_LOCAL3, "local4" => Syslog::LOG_LOCAL4, "local5" => Syslog::LOG_LOCAL5, "local6" => Syslog::LOG_LOCAL6, "local7" => Syslog::LOG_LOCAL7 }
Class Method Summary collapse
-
.run(options = {}) ⇒ Object
class SysLoggerWatcher.
Class Method Details
.run(options = {}) ⇒ Object
class SysLoggerWatcher
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/oversip/syslogger_process.rb', line 68 def self.run ={} $0 = ::OverSIP.master_name + "_syslogger" = ::Syslog::LOG_PID | ::Syslog::LOG_NDELAY syslog_facility = SYSLOG_FACILITY_MAPPING[::OverSIP.configuration[:core][:syslog_facility]] ::Syslog.open(::OverSIP.master_name, , syslog_facility) ppid = ::Process.ppid at_exit do ::Syslog.notice sprintf("%7s %s", "INFO:", "<syslogger> syslogger process terminated") exit! end EM.run do begin syslogger_mq = ::POSIX_MQ.new ::OverSIP.syslogger_mq_name, ::IO::RDONLY | ::IO::NONBLOCK ::EM::PosixMQ.run syslogger_mq, SysLoggerWatcher # Change process permissions if requested. ::OverSIP::Launcher.set_user_group([:user], [:group]) rescue => e ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> #{e.class}: #{e}") ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> syslogger process terminated") exit! 1 end # Periodically check that master process remains alive and # die otherwise. ::EM.add_periodic_timer(1) do if ::Process.ppid != ppid # Wait 0.5 seconds. Maybe the master process has been killed properly and just now # it's sending us the QUIT signal. ::EM.add_timer(0.5) do ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> master process died, syslogger process terminated") exit! 1 end end end ::EM.error_handler do |e| ::Syslog.crit sprintf("%7s %s", "CRIT:", "<syslogger> error raised during event loop and rescued by EM.error_handler: #{e.} (#{e.class})\n#{(e.backtrace || [])[0..3].join("\n")}") end ::Syslog.info sprintf("%7s %s", "INFO:", "<syslogger> syslogger process (PID #{$$}) ready") end end |