summaryrefslogtreecommitdiff
path: root/config/unicorn.rb
diff options
context:
space:
mode:
authorJulian Pawlowski <julian.pawlowski@gmail.com>2013-01-16 23:24:41 +0100
committerJulian Pawlowski <julian.pawlowski@gmail.com>2013-01-16 23:24:41 +0100
commit86b9ba00a88b455f88ced10cf959660b96113c88 (patch)
treec39865d4c4d2e54cbac3239887754e2ac642481f /config/unicorn.rb
parentc2f63b8bf288903a68c562cdf9353e6840a7cb61 (diff)
better process handling
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