Peter Hall
2012-Dec-05 05:19 UTC
Fwd: Issue starting unicorn with non-ActiveRecord Rails app
Hi, I''m trying to use unicorn in a test deployment of a Rails app that uses Mongoid, so Activerecord isn''t included in the app. When I start unicorn through Capistrano though, the stderr log fills up endlessly with identical ActiveRecord-related errors: I, [2012-12-05T04:19:25.375952 #5096] INFO -- : Refreshing Gem list I, [2012-12-05T04:19:32.941249 #5096] INFO -- : listening on addr=/var/www/webapps/fugu-cp/shared/pids/unicorn.sock fd=11 I, [2012-12-05T04:19:32.990825 #5096] INFO -- : master process ready E, [2012-12-05T04:19:33.108183 #5110] ERROR -- : uninitialized constant ActiveRecord (NameError) /var/www/webapps/fugu-cp/current/config/unicorn.rb:68:in `block in reload'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:569:in `call'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:569:in `init_worker_process'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:593:in `worker_loop'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:491:in `spawn_missing_workers'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:141:in `start'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/bin/unicorn_rails:209:in `<top (required)>'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/bin/unicorn_rails:23:in `load'' /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/bin/unicorn_rails:23:in `<main>'' This repeats until I kill Unicorn. If you''re curious, the way I''m starting Unicorn in the deploy file is as follows: set :unicorn_rails, "#{deploy_to}/shared/bundle/ruby/1.9.1/bin/unicorn_rails" run "cd #{latest_release} && bundle exec \"#{unicorn_rails} -c #{deploy_to}/current/config/unicorn.rb -D -E #{rails_env}\"" Incidentally, if there''s a standard Unicorn include file for Capistrano so I don''t have to specify my own tasks to start and stop it, I''d be grateful to know, because I couldn''t find one and had to use a very heavily-modified version of something I copied+pasted from this gist: https://gist.github.com/1003099 Thanks,
Eric Wong
2012-Dec-05 07:45 UTC
Fwd: Issue starting unicorn with non-ActiveRecord Rails app
Peter Hall <peter.hall at localstars.com> wrote:> Hi, > > I''m trying to use unicorn in a test deployment of a Rails app that > uses Mongoid, so Activerecord isn''t included in the app. When I start > unicorn through Capistrano though, the stderr log fills up endlessly > with identical ActiveRecord-related errors: > > I, [2012-12-05T04:19:25.375952 #5096] INFO -- : Refreshing Gem list > I, [2012-12-05T04:19:32.941249 #5096] INFO -- : listening on > addr=/var/www/webapps/fugu-cp/shared/pids/unicorn.sock fd=11 > I, [2012-12-05T04:19:32.990825 #5096] INFO -- : master process ready > E, [2012-12-05T04:19:33.108183 #5110] ERROR -- : uninitialized > constant ActiveRecord (NameError)Hi Peter, this doesn''t seem like an issue specific to unicorn... Can you reproduce this issue using another server, perhaps: rackup -s webrick -E #{rails_env} ? <snip>> This repeats until I kill Unicorn. > > If you''re curious, the way I''m starting Unicorn in the deploy file is > as follows:Which version of Rails is this? Folks more familiar with modern Rails than myself should be able to help given more information. (Maybe asking on a Rails-oriented list can help, too). I do remember it was possible to disable parts of Rails back in the day. Most of my Rails knowledge is stuck in the Rails 1.x-era, though...> set :unicorn_rails, "#{deploy_to}/shared/bundle/ruby/1.9.1/bin/unicorn_rails" > run "cd #{latest_release} && bundle exec \"#{unicorn_rails} -c > #{deploy_to}/current/config/unicorn.rb -D -E #{rails_env}\""Probably unrelated to the issue at hand, but "unicorn" is preferred if you''re on Rails >=3.
Daniel Condomitti
2012-Dec-05 07:48 UTC
Issue starting unicorn with non-ActiveRecord Rails app
On Tuesday, December 4, 2012 at 9:19 PM, Peter Hall wrote:> Hi, > > I''m trying to use unicorn in a test deployment of a Rails app that > uses Mongoid, so Activerecord isn''t included in the app. When I start > unicorn through Capistrano though, the stderr log fills up endlessly > with identical ActiveRecord-related errors: > > I, [2012-12-05T04:19:25.375952 #5096] INFO -- : Refreshing Gem list > I, [2012-12-05T04:19:32.941249 #5096] INFO -- : listening on > addr=/var/www/webapps/fugu-cp/shared/pids/unicorn.sock fd=11 > I, [2012-12-05T04:19:32.990825 #5096] INFO -- : master process ready > E, [2012-12-05T04:19:33.108183 #5110] ERROR -- : uninitialized > constant ActiveRecord (NameError) > /var/www/webapps/fugu-cp/current/config/unicorn.rb:68:in `block in reload'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:569:in > `call'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:569:in > `init_worker_process'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:593:in > `worker_loop'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:491:in > `spawn_missing_workers'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/lib/unicorn/http_server.rb:141:in > `start'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/gems/unicorn-4.4.0/bin/unicorn_rails:209:in > `<top (required)>'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/bin/unicorn_rails:23:in `load'' > /var/www/webapps/fugu-cp/shared/bundle/ruby/1.9.1/bin/unicorn_rails:23:in > `<main>'' > > This repeats until I kill Unicorn. > > If you''re curious, the way I''m starting Unicorn in the deploy file is > as follows: > > set :unicorn_rails, "#{deploy_to}/shared/bundle/ruby/1.9.1/bin/unicorn_rails" > run "cd #{latest_release} && bundle exec \"#{unicorn_rails} -c > #{deploy_to}/current/config/unicorn.rb -D -E #{rails_env}\"" > > Incidentally, if there''s a standard Unicorn include file for > Capistrano so I don''t have to specify my own tasks to start and stop > it, I''d be grateful to know, because I couldn''t find one and had to > use a very heavily-modified version of something I copied+pasted from > this gist: https://gist.github.com/1003099 > > Thanks,What''s L68 of your config/unicorn.rb file look like? Check to see if you have copied/pasted a line that references ActiveRecord in the before_fork or after_fork blocks. A lot of unicorn examples have an ActiveRecord::Base.connection.disconnect! (with a defined?(ActiveRecord::Base) but that might not be present in your config) statement to ensure that AR connections aren''t shared between the master and worker processes.
> What''s L68 of your config/unicorn.rb file look like? Check to see if you have copied/pasted a line that references ActiveRecord in the before_fork or after_fork blocks. > > A lot of unicorn examples have an ActiveRecord::Base.connection.disconnect! (with a defined?(ActiveRecord::Base) but that might not be present in your config) statement to ensure that AR connections aren''t shared between the master and worker processes.Aha! Thanks Daniel. =) I''m such an idiot =oP I totally missed that it was in my own code - including the path on the top line of the trace =|. The reason I presumed it wasn''t is because I copied+pasted most of the unicorn config, so I didn''t remember *writing* any AR-specific code. I guess it should work if I take that out! The line actually turned out to be ActiveRecord::Base.establish_connection Thanks again! *slaps forehead*
Reasonably Related Threads
- Rails 4.0 has_many_through and fields_for
- Workers getting broken after some time
- Ruby 2.0 Bad file descriptor (Errno::EBADF)
- [PATCH] Start the server if another user has a PID matching our stale pidfile.
- [PATCH] construct listener_fds Hash in 1.8 compatible way