summaryrefslogtreecommitdiff
path: root/config/unicorn.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-17 09:52:00 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-01-17 09:52:00 +0100
commitc09073174bb51561030a48f95f283b63b0ddae34 (patch)
treefb82681cf83c4a9cbe6fe310f2ea8942c8311d4f /config/unicorn.rb
parent416a9c563ed52b2b4f5350b8a069313f5843489c (diff)
parent85d8dc12c3963f78ea1db4089c6ff2fa6ec205e9 (diff)
Merge branch 'develop' of github.com:amooma/GS5 into develop
Diffstat (limited to 'config/unicorn.rb')
-rw-r--r--config/unicorn.rb43
1 files changed, 21 insertions, 22 deletions
diff --git a/config/unicorn.rb b/config/unicorn.rb
index d379569..8157562 100644
--- a/config/unicorn.rb
+++ b/config/unicorn.rb
@@ -1,35 +1,34 @@
-worker_processes 2
-working_directory "/opt/GS5/"
+APP_ROOT = File.expand_path(File.dirname(File.dirname(__FILE__)))
+
+worker_processes 1
+working_directory APP_ROOT
-# This loads the application in the master process before forking
-# worker processes
-# Read more about it here:
-# http://unicorn.bogomips.org/Unicorn/Configurator.html
preload_app true
timeout 30
-# This is where we specify the socket.
-# We will point the upstream Nginx module to this socket later on
-listen "/opt/GS5/tmp/sockets/unicorn.sock", :backlog => 64
+listen APP_ROOT + "/tmp/sockets/unicorn.sock", :backlog => 64
-pid "/opt/GS5/tmp/pids/unicorn.pid"
+pid APP_ROOT + "/tmp/pids/unicorn.pid"
-# Set the path of the log files inside the log folder of the testapp
-stderr_path "/opt/GS5/log/unicorn.stderr.log"
-stdout_path "/opt/GS5/log/unicorn.stdout.log"
+stderr_path APP_ROOT + "/log/unicorn.stderr.log"
+stdout_path APP_ROOT + "/log/unicorn.stdout.log"
before_fork do |server, worker|
-# This option works in together with preload_app true setting
-# What is does is prevent the master process from holding
-# the database connection
- defined?(ActiveRecord::Base) and
- ActiveRecord::Base.connection.disconnect!
+ 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|
-# Here we are establishing the connection after forking worker
-# processes
- defined?(ActiveRecord::Base) and
- ActiveRecord::Base.establish_connection
+ defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection
+ child_pid = server.config[:pid].sub('.pid', ".#{worker.nr}.pid")
+ system("echo #{Process.pid} > #{child_pid}")
end