Skip to content

Commit

Permalink
Rework systemd integration so it does not activate when run in other …
Browse files Browse the repository at this point in the history
…binaries, like sidekiqswarm or a custom Sidekiq launcher, #4511
  • Loading branch information
mperham committed Mar 26, 2020
1 parent b48d539 commit 2504d0b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions Changes.md
Expand Up @@ -6,6 +6,7 @@ HEAD
---------

- Fix: Do not connect to redis at ruby vm exit when not needed. [#4502]
- Refactor systemd integration to work better with custom binaries [#4511]
- Remove Redis connection naming [#4479]

6.0.6
Expand Down
19 changes: 19 additions & 0 deletions bin/sidekiq
Expand Up @@ -6,9 +6,28 @@ $TESTING = false

require_relative '../lib/sidekiq/cli'

def integrate_with_systemd
return unless ENV["NOTIFY_SOCKET"]

Sidekiq.configure_server do |config|
Sidekiq.logger.info "Enabling systemd notification integration"
require "sidekiq/sd_notify"
config.on(:startup) do
Sidekiq::SdNotify.ready
end
config.on(:shutdown) do
Sidekiq::SdNotify.stopping
end
Sidekiq.start_watchdog if Sidekiq::SdNotify.watchdog?
end
end

begin
cli = Sidekiq::CLI.instance
cli.parse

integrate_with_systemd

cli.run
rescue => e
raise e if $DEBUG
Expand Down
16 changes: 1 addition & 15 deletions lib/sidekiq/systemd.rb
Expand Up @@ -16,23 +16,9 @@ def self.start_watchdog
Sidekiq.logger.info "Pinging systemd watchdog every #{ping_f.round(1)} sec"
Thread.new do
loop do
Sidekiq::SdNotify.watchdog
sleep ping_f
Sidekiq::SdNotify.watchdog
end
end
end
end

if ENV["NOTIFY_SOCKET"]
Sidekiq.configure_server do |config|
Sidekiq.logger.info "Enabling systemd notification integration"
require "sidekiq/sd_notify"
config.on(:startup) do
Sidekiq::SdNotify.ready
end
config.on(:shutdown) do
Sidekiq::SdNotify.stopping
end
Sidekiq.start_watchdog if Sidekiq::SdNotify.watchdog?
end
end

0 comments on commit 2504d0b

Please sign in to comment.