Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
feat(appserver): re-establish database connections when preloading app
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgon committed Jan 5, 2019
1 parent 27bad91 commit db17de6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions templates/default/puma.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ directory "<%= @deploy_dir %>/current"

<% if @out[:preload_app] %>
preload_app!
on_worker_boot do
next unless defined?(ActiveRecord::Base) && defined?(Rails)
next unless Gem::Requirement.new('>= 4.1')
.satisfied_by?(Gem::Version.new(Rails.version))
ActiveRecord::Base.establish_connection
end
<% end %>

# Set the environment in which the rack's app will run. The value must be a string.
Expand Down
8 changes: 8 additions & 0 deletions templates/default/unicorn.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ stderr_path "<%= @deploy_dir %>/shared/log/unicorn.stderr.log"
stdout_path "<%= @deploy_dir %>/shared/log/unicorn.stdout.log"

preload_app <%= @out[:preload_app] %>
<% if @out[:preload_app] %>
after_fork do |_server, _worker|

This comment has been minimized.

Copy link
@inopinatus

inopinatus Jun 21, 2019

Contributor

This block never runs, because another after_fork (doing practically the same thing) is specified later in the file.

This comment has been minimized.

Copy link
@ajgon

ajgon Jun 28, 2019

Author Owner

Nic catch! Fixed it in: c0b0e84 - thank you!

next unless defined?(ActiveRecord::Base) && defined?(Rails)
next unless Gem::Requirement.new('>= 4.1')
.satisfied_by?(Gem::Version.new(Rails.version))
ActiveRecord::Base.establish_connection
end
<% end %>
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)

# ensure Unicorn doesn't use a stale Gemfile when restarting
Expand Down

0 comments on commit db17de6

Please sign in to comment.