lib/service_skeleton.rb in service_skeleton-0.0.0.3.g1269800.1.gaaa2fa1 vs lib/service_skeleton.rb in service_skeleton-0.0.0.3.g1269800.1.gaaa2fa1.6.gf4e308e

- old
+ new

@@ -36,18 +36,21 @@ @env = env @config = (self.class.instance_variable_get(:@config_class) || ServiceSkeleton::Config).new(env, self) @logger = @config.logger @op_mutex = Mutex.new - setup_metrics - setup_signals + initialize_metrics + initialize_signals end def start @op_mutex.synchronize { @thread = Thread.current } begin + logger.info(logloc) { "Starting service #{service_name}" } + logger.info(logloc) { (["Environment:"] + config.env.map { |k, v| "#{k}=#{v.inspect}" }).join("\n ") } + start_metrics_server start_signal_handler run rescue ServiceSkeleton::Terminate # This one is OK @@ -110,11 +113,11 @@ end end #:nocov: end - def setup_metrics + def initialize_metrics @metrics = Prometheus::Client::Registry.new Frankenstein::RubyGCMetrics.register(@metrics) Frankenstein::RubyVMMetrics.register(@metrics) Frankenstein::ProcessMetrics.register(@metrics) @@ -124,11 +127,11 @@ end def start_metrics_server if config.metrics_port - logger.info(self.class.to_s) { "Starting metrics server on port #{config.metrics_port}" } + logger.info(logloc) { "Starting metrics server on port #{config.metrics_port}" } @metrics_server = Frankenstein::Server.new( port: config.metrics_port, logger: logger, metrics_prefix: :metrics_server, @@ -136,11 +139,12 @@ ) @metrics_server.run end end - def setup_signals - @signal_handler = ServiceSkeleton::SignalHandler.new(logger: logger, service: self, signal_counter: metrics.counter(:"#{self.service_name}_signals_handled_total", "How many of each type of signal have been handled")) + def initialize_signals + metrics.counter(:"#{self.service_name}_signals_handled_total", "How many of each type of signal have been handled") + @signal_handler = ServiceSkeleton::SignalHandler.new(logger: logger, service: self, signal_counter: metrics.signals_handled_total) @signal_handler.hook_signal("USR1") do logger.level -= 1 unless logger.level == Logger::DEBUG logger.info($0) { "Received SIGUSR1; log level is now #{Logger::SEV_LABEL[logger.level]}." } end