class Object
Public Instance Methods
booted_workers()
click to toggle source
# File lib/puma/plugin/systemd.rb, line 83 def booted_workers stats.fetch(:booted_workers, 1) end
clustered?()
click to toggle source
# File lib/puma/plugin/systemd.rb, line 75 def clustered? stats.has_key?(:workers) end
common_message(stats)
click to toggle source
# File lib/puma/plugin/systemd.rb, line 87 def common_message(stats) "{ #{stats[:running]}/#{stats[:max_threads]} threads, #{stats[:pool_capacity]} available, #{stats[:backlog]} backlog }" end
start(launcher)
click to toggle source
# File lib/puma/plugin/systemd.rb, line 11 def start(launcher) require_relative '../sd_notify' launcher.log_writer.log "* Enabling systemd notification integration" # hook_events launcher.events.on_booted { Puma::SdNotify.ready } launcher.events.on_stopped { Puma::SdNotify.stopping } launcher.events.on_restart { Puma::SdNotify.reloading } # start watchdog if Puma::SdNotify.watchdog? ping_f = watchdog_sleep_time in_background do launcher.log_writer.log "Pinging systemd watchdog every #{ping_f.round(1)} sec" loop do sleep ping_f Puma::SdNotify.watchdog end end end # start status loop instance = self sleep_time = 1.0 in_background do launcher.log_writer.log "Sending status to systemd every #{sleep_time.round(1)} sec" loop do sleep sleep_time # TODO: error handling? Puma::SdNotify.status(instance.status) end end end
stats()
click to toggle source
# File lib/puma/plugin/systemd.rb, line 71 def stats Puma.stats_hash end
status()
click to toggle source
# File lib/puma/plugin/systemd.rb, line 48 def status if clustered? messages = stats[:worker_status].map do |worker| common_message(worker[:last_status]) end.join(',') "Puma #{Puma::Const::VERSION}: cluster: #{booted_workers}/#{workers}, worker_status: [#{messages}]" else "Puma #{Puma::Const::VERSION}: worker: #{common_message(stats)}" end end
watchdog_sleep_time()
click to toggle source
# File lib/puma/plugin/systemd.rb, line 62 def watchdog_sleep_time usec = Integer(ENV["WATCHDOG_USEC"]) sec_f = usec / 1_000_000.0 # "It is recommended that a daemon sends a keep-alive notification message # to the service manager every half of the time returned here." sec_f / 2 end
workers()
click to toggle source
# File lib/puma/plugin/systemd.rb, line 79 def workers stats.fetch(:workers, 1) end