summaryrefslogtreecommitdiff
path: root/config/unicorn.rb
diff options
context:
space:
mode:
Diffstat (limited to 'config/unicorn.rb')
-rw-r--r--config/unicorn.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/config/unicorn.rb b/config/unicorn.rb
new file mode 100644
index 0000000..8157562
--- /dev/null
+++ b/config/unicorn.rb
@@ -0,0 +1,34 @@
+APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
+
+worker_processes 1
+working_directory APP_ROOT
+
+preload_app true
+
+timeout 30
+
+listen APP_ROOT + "/tmp/sockets/unicorn.sock", :backlog => 64
+
+pid APP_ROOT + "/tmp/pids/unicorn.pid"
+
+stderr_path APP_ROOT + "/log/unicorn.stderr.log"
+stdout_path APP_ROOT + "/log/unicorn.stdout.log"
+
+before_fork do |server, worker|
+ defined?(ActiveRecord::Base) && ActiveRecord::Base.connection.disconnect!
+
+ old_pid = Rails.root + '/tmp/pids/unicorn.pid.oldbin'
+ if File.exists?(old_pid) && server.pid != old_pid
+ begin
+ Process.kill("QUIT", File.read(old_pid).to_i)
+ rescue Errno::ENOENT, Errno::ESRCH
+ puts "Old master alerady dead"
+ end
+ end
+end
+
+after_fork do |server, worker|
+ defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
+ child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
+ system("echo #{Process.pid} > #{child_pid}")
+end