From 4618990e4efcf1353428bbe032f0b19aefafb2f0 Mon Sep 17 00:00:00 2001 From: Enrico Stano Date: Fri, 2 Feb 2018 16:41:15 +0100 Subject: [PATCH] Add unicorn configuration --- config/unicorn.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 config/unicorn.rb diff --git a/config/unicorn.rb b/config/unicorn.rb new file mode 100644 index 000000000..68fc5017c --- /dev/null +++ b/config/unicorn.rb @@ -0,0 +1,29 @@ +app_path = File.expand_path(File.dirname(__FILE__) + '/..') + +worker_processes 2 + +listen 8080, tcp_nopush: true + +working_directory app_path + +pid app_path + '/tmp/unicorn.pid' + +stderr_path '/var/www/timeoverflow/shared/log/unicorn.err.log' +stdout_path '/var/www/timeoverflow/shared/log/unicorn.std.log' + +# Load the app up before forking +# Combine Ruby 2.0.0+ with "preload_app true" for memory savings +preload_app true + +before_fork do |server, worker| + # the following is highly recomended for Rails + "preload_app true" + # as there's no need for the master process to hold a connection + defined?(ActiveRecord::Base) and + ActiveRecord::Base.connection.disconnect! +end + +after_fork do |server, worker| + # the following is *required* for Rails + "preload_app true" + defined?(ActiveRecord::Base) and + ActiveRecord::Base.establish_connection +end