Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Puma spawner #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions lib/copycopter_client/process_guard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ def start_polling
end

def spawner?
passenger_spawner? || unicorn_spawner?
return false if ENV['COPYCOPTER_OFF']
puma_spawner? || passenger_spawner? || unicorn_spawner?
end

def puma_spawner?
$0.include?('puma')
end

def passenger_spawner?
Expand All @@ -42,13 +47,28 @@ def unicorn_spawner?
end

def register_spawn_hooks
if defined?(PhusionPassenger)
if defined?(Puma::Cluster)
register_puma_hook
elsif defined?(PhusionPassenger)
register_passenger_hook
elsif defined?(Unicorn::HttpServer)
register_unicorn_hook
end
end

def register_puma_hook
@logger.info("Registered Puma fork hook")
poller = @poller

Puma::Cluster.class_eval do
alias_method :worker_without_copycopter, :worker
define_method :worker do |index, master|
poller.start
worker_without_copycopter(index, master)
end
end
end

def register_passenger_hook
@logger.info("Registered Phusion Passenger fork hook")
PhusionPassenger.on_event(:starting_worker_process) do |forked|
Expand Down