nathanl / authority

*CURRENTLY UNMAINTAINED*. Authority helps you authorize actions in your Rails app. It's ORM-neutral and has very little fancy syntax; just group your models under one or more Authorizer classes and write plain Ruby methods on them.
MIT License
1.21k stars 67 forks source link

Deployment issue with Capistrano #61

Closed grcarey closed 11 years ago

grcarey commented 11 years ago

This is a cross-post from me at stackoverflow.

http://stackoverflow.com/questions/19238540/error-when-deploying-the-authority-gem-with-capistrano

If a get a response from there I will post it back here.

I'm deploying a rails4 app from a dev machine to a server. This deployment has been working smoothly.

I have added authorisation to my application using the authority gem. When I run ./bin/cap deploy I now get the error in the unicorn log that is listed below.

All of the files created with rails g authority:install on the dev machine have been committed to git and are being deployed to the server using ./bin/cap deploy.

Any help appreciated.

I, [2013-10-08T14:06:42.579240 #2021]  INFO -- : worker=0 spawning...
I, [2013-10-08T14:06:42.583257 #3594]  INFO -- : worker=0 spawned pid=3594
I, [2013-10-08T14:06:42.583904 #3594]  INFO -- : Refreshing Gem list
E, [2013-10-08T14:06:42.743225 #3588] ERROR -- : uninitialized constant Authority (NameError)
/home/deployer/apps/app-name/releases/20131008015646/config/initializers/authority.rb:1:in `<top (required)>'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:609:in `block (2 levels) in <class:Engine>'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `each'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/engine.rb:608:in `block in <class:Engine>'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `instance_exec'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:30:in `run'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:150:in `block in tsort_each'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:210:in `block (2 levels) in each_strongly_connected_component_from'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:219:in `each_strongly_connected_component_from'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:209:in `block in each_strongly_connected_component_from'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `each'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:44:in `tsort_each_child'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:203:in `each_strongly_connected_component_from'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:182:in `block in each_strongly_connected_component'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:180:in `each'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:180:in `each_strongly_connected_component'
/home/deployer/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/tsort.rb:148:in `tsort_each'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/initializable.rb:54:in `run_initializers'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/application.rb:215:in `initialize!'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/railties-4.0.0/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/deployer/apps/app-name/releases/20131008015646/config/environment.rb:5:in `<top (required)>'
config.ru:4:in `require'
config.ru:4:in `block in <main>'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn.rb:48:in `eval'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn.rb:48:in `block in builder'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:722:in `call'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:722:in `build_app!'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:595:in `init_worker_process'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:615:in `worker_loop'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:511:in `maintain_worker_count'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/lib/unicorn/http_server.rb:277:in `join'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/gems/unicorn-4.6.3/bin/unicorn:126:in `<top (required)>'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `load'
/home/deployer/apps/app-name/shared/bundle/ruby/2.0.0/bin/unicorn:23:in `<main>'
E, [2013-10-08T14:06:42.758457 #2021] ERROR -- : reaped #<Process::Status: pid 3588 exit 1> worker=1
nathanl commented 11 years ago

That's odd.

I don't think there's anything specific to Authority that's going wrong here; your config/initializers/authority.rb is being loaded, it refers to the Authority constant, and that constant isn't loaded yet.

Authority doesn't do anything to load the Authority constant; it's declared in lib/authority.rb, which should be required by your Gemfile.

Any chance you put gem 'authority' in your Gemfile in a section which doesn't apply to production?

grcarey commented 11 years ago

Thanks for the response Nathan. The authority gem is not particular to a specific environment. It is bundle installed in the production environment.

nathanl commented 11 years ago

If you run RAILS_ENV=production script/rails console on your production machine and then type Authority, do you get a missing constant? What about if you try a constant from another gem you're using?

I'm wondering if you're having this problem with Authority only, or if it's just the first initializer that runs (maybe they use alphabetical order).

Also, would you mind posting the contents of your Gemfile?

grcarey commented 11 years ago

Hi Nathan,

In the end I wiped my staging environment, changed nothing in my dev environment, and re-ran the cap deploy and it worked. Not sure what the reason for this was.

nathanl commented 11 years ago

@grcarey My usual explanation for such things is "computer gnomes." They are quite mischievous. ;)