Skip to content

Commit 33b9b15

Browse files
committed
a better after_fork block without duplicating the db info
1 parent 65049bf commit 33b9b15

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

‎config/unicorn.rb‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,9 @@
1616
end
1717

1818
after_fork do |server, worker|
19-
# the following is *required* for Rails + "preload_app true",
20-
defined?(ActiveRecord::Base) and
21-
ActiveRecord::Base.establish_connection(
22-
:adapter => 'postgresql',
23-
:encoding => 'unicode',
24-
:pool => 5,
25-
:database => ENV['STRINGER_DATABASE'] || "stringer",
26-
:username => ENV['STRINGER_DATABASE_USERNAME'],
27-
:password => ENV['STRINGER_DATABASE_PASSWORD']
28-
)
19+
if defined?(ActiveRecord::Base)
20+
env = ENV['RACK_ENV'] || "development"
21+
config = YAML::load(File.open('config/database.yml'))[env]
22+
ActiveRecord::Base.establish_connection(config)
23+
end
2924
end

0 commit comments

Comments
 (0)