lib/capistrano/devops/templates/unicorn.erb in capistrano-devops-0.0.12 vs lib/capistrano/devops/templates/unicorn.erb in capistrano-devops-0.0.13
- old
+ new
@@ -4,5 +4,21 @@
stdout_path "<%= fetch(:unicorn_log) %>"
listen "/tmp/unicorn.<%= fetch(:application) %>.sock"
worker_processes <%= fetch(:unicorn_workers) %>
timeout <%= fetch(:unicorn_timeout) %>
+
+preload_app true
+
+before_fork do |server, worker|
+ # Disconnect since the database connection will not carry over
+ if defined? ActiveRecord::Base
+ ActiveRecord::Base.connection.disconnect!
+ end
+end
+
+after_fork do |server, worker|
+ # Start up the database connection again in the worker
+ if defined?(ActiveRecord::Base)
+ ActiveRecord::Base.establish_connection
+ end
+end
\ No newline at end of file