Sha256: 22eb058226136c6e90e20ce4f3a6e1f75193862f3a44dab961c4bba53059a993

Contents?: true

Size: 940 Bytes

Versions: 51

Compression:

Stored size: 940 Bytes

Contents

# frozen_string_literal: true

require 'sd_notify'

module Puma
  class Systemd
    def initialize(events)
      @events = events
    end

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

    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

    private

    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

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

Version data entries

51 entries across 48 versions & 5 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/puma-5.5.2/lib/puma/systemd.rb
puma-5.5.2-java lib/puma/systemd.rb
puma-5.5.2 lib/puma/systemd.rb
puma-5.5.1-java lib/puma/systemd.rb
puma-5.5.1 lib/puma/systemd.rb
puma-5.5.0-java lib/puma/systemd.rb
puma-5.5.0 lib/puma/systemd.rb
piesync-puma-5.4.0.1 lib/puma/systemd.rb
puma-5.4.0-java lib/puma/systemd.rb
puma-5.4.0 lib/puma/systemd.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/puma-5.2.2/lib/puma/systemd.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/puma-5.2.1/lib/puma/systemd.rb
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/puma-5.1.1/lib/puma/systemd.rb
puma-5.3.2-java lib/puma/systemd.rb
puma-5.3.2 lib/puma/systemd.rb
puma-5.3.1-java lib/puma/systemd.rb
puma-5.3.1 lib/puma/systemd.rb
puma-5.3.0-java lib/puma/systemd.rb
puma-5.3.0 lib/puma/systemd.rb
puma-5.2.2-java lib/puma/systemd.rb