11

I have a strange problem in staging after i migrated to unicorn from passenger.

I configured unicorn for both development and staging environment . its working in development but not in staging. In development its listening to 8080 where as in staging its listening to a unix socket. Will that make any diferrence ? Especially in production kinda env?

This is what happens when i run it in staging

  1. It takes almost 100% CPU while starting
  2. sometimes it settles down and i am able to use it
  3. *But most of the times it hangs** and i had to kill it.

I have logged a question regarding this issue click here

This is what i see in unicorn.stderr.log

I, [2011-08-26T09:02:53.324286 #5026]  INFO -- : unlinking existing socket=/home/krishnaprasad/project_name/tmp/sockets/unicorn.sock
I, [2011-08-26T09:02:53.324502 #5026]  INFO -- : listening on addr=/home/krishnaprasad/project_name/tmp/sockets/unicorn.sock fd=3
I, [2011-08-26T09:02:53.324860 #5026]  INFO -- : Refreshing Gem list

why does it try to refresh the gems ? is there any way to avoid it in config file ?

this is what i have in config/unicorn_staging.rb

# unicorn_rails -c /config/unicorn_staging.rb -E staging -D

rails_env = 'staging'

working_directory "/home/krishnaprasad/Projects/project_name"
worker_processes 1
preload_app true
timeout 90

rails_root = "/home/krishnaprasad/Projects/project_name"
listen "#{rails_root}/tmp/sockets/unicorn.sock", :backlog => 2048

pid "#{rails_root}/tmp/pids/unicorn.pid"
stderr_path "#{rails_root}/log/unicorn.log"
stdout_path "#{rails_root}/log/unicorn.log"

GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)

before_fork do |server, worker|
  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
      # someone else did our job for us
    end
  end
end

after_fork do |server, worker|
  ActiveRecord::Base.establish_connection
end

Any help highly appreciated. Thanks in advance

Community
  • 1
  • 1
Krishna Prasad Varma
  • 4,670
  • 5
  • 29
  • 41
  • Did you ever figure this out? I experienced the same problem. – David May 08 '12 at 21:13
  • i removed this line and found it somewhat working but still its slow after_fork do |server, worker| ActiveRecord::Base.establish_connection end – Krishna Prasad Varma May 12 '12 at 06:55
  • Seems like removing that line will cause issues with shared database handles in your unicorn subprocesses. I ended up just not being able to run Unicorn in daemon mode with preload app. Once I disabled preload app, it stopped causing problems. – David May 20 '12 at 18:45
  • PS - I'm using Sinatra rather than Rails, but encountered what seems to be the same problem as you, so it probably isn't framework specific. – David May 20 '12 at 18:46

2 Answers2

0

Make sure your code is free of syntax errors!

For me fixing a syntax error (in one of my controllers) ended the loop and started Unicorn properly. I did not get any error messages in Unicorn, you might want to try to start using WebRat and see if an error pops up.

mmlac
  • 1,091
  • 1
  • 9
  • 24
0

For me, it was the database connection wasn't configured correctly. It seems like sometimes it reports this at the console, sometimes it just spins.

Matthew Bloch
  • 357
  • 2
  • 10