diff options
Diffstat (limited to 'config')
-rw-r--r-- | config/unicorn.rb | 43 |
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 |