123456789_123456789_123456789_123456789_123456789_

Class: Puma::Systemd

Relationships & Source Files
Inherits: Object
Defined in: lib/puma/systemd.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(log_writer, events) ⇒ Systemd

[ GitHub ]

  
# File 'lib/puma/systemd.rb', line 7

def initialize(log_writer, events)
  @log_writer = log_writer
  @events = events
end

Instance Method Details

#hook_events

[ GitHub ]

  
# File 'lib/puma/systemd.rb', line 12

def hook_events
  @events.on_booted { SdNotify.ready }
  @events.on_stopped { SdNotify.stopping }
  @events.on_restart { SdNotify.reloading }
end

#log(str) (private)

[ GitHub ]

  
# File 'lib/puma/systemd.rb', line 43

def log(str)
  @log_writer.log(str)
end

#start_watchdog

[ GitHub ]

  
# File 'lib/puma/systemd.rb', line 18

def start_watchdog
  return unless SdNotify.watchdog?

  ping_f = watchdog_sleep_time

  log "Pinging systemd watchdog every #{ping_f.round(1)} sec"
  Thread.new do
    loop do
      sleep ping_f
      SdNotify.watchdog
    end
  end
end

#watchdog_sleep_time (private)

[ GitHub ]

  
# File 'lib/puma/systemd.rb', line 34

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