theforeman / foreman_hooks

Run custom hook scripts on Foreman events
http://m0dlx.com/blog/Extending_Foreman_quickly_with_hook_scripts.html
GNU General Public License v3.0
56 stars 50 forks source link

Foreman 1.8.2 crashes after installing foreman_hooks #26

Closed hufman closed 9 years ago

hufman commented 9 years ago

I am using Ubuntu 14.04 and the Foreman 1.8 deb repo. I have a Foreman 1.8.2 instance that I upgraded from 1.7.2. After I install foreman_hooks, either with the deb of 0.3.7 or the latest gem of 0.3.8, Foreman crashes on any web page with the following message:

Web application could not be started

undefined local variable or method `belongs_to_host' for #<Class:0x0000000432a9e8> (NameError)
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activerecord-3.2.21/lib/active_record/dynamic_matchers.rb:55:in `method_missing'
  /usr/share/foreman/app/models/report.rb:6:in `<class:Report>'
  /usr/share/foreman/app/models/report.rb:1:in `<top (required)>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `block in require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:236:in `load_dependency'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:359:in `require_or_load'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:502:in `load_missing_constant'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:83:in `load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:192:in `block in const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:514:in `load_missing_constant'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:83:in `load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:192:in `block in const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:514:in `load_missing_constant'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:83:in `load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:192:in `block in const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `const_missing'
  /usr/share/foreman/app/models/concerns/hostext/search.rb:18:in `block in <module:Search>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/concern.rb:121:in `class_eval'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/concern.rb:121:in `append_features'
  /usr/share/foreman/app/models/host/managed.rb:3:in `include'
  /usr/share/foreman/app/models/host/managed.rb:3:in `<class:Managed>'
  /usr/share/foreman/app/models/host/managed.rb:1:in `<top (required)>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `block in require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:236:in `load_dependency'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:251:in `require'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:359:in `require_or_load'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:502:in `load_missing_constant'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:83:in `load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:192:in `block in const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/inflector/methods.rb:230:in `block in constantize'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/inflector/methods.rb:229:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/inflector/methods.rb:229:in `constantize'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
  /usr/share/foreman/app/models/host.rb:15:in `method_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks/orchestration_hook.rb:8:in `block in <module:OrchestrationHook>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/concern.rb:121:in `class_eval'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/concern.rb:121:in `append_features'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:71:in `include'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:71:in `attach_hook'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:85:in `block in load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:84:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:84:in `load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:192:in `block in const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:514:in `load_missing_constant'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:83:in `load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:192:in `block in const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:514:in `load_missing_constant'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/foreman_hooks-0.3.8/lib/foreman_hooks.rb:83:in `load_missing_constant_with_hooks'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:192:in `block in const_missing'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:190:in `const_missing'
  /usr/share/foreman/config/initializers/active_record_extensions.rb:2:in `<class:Base>'
  /usr/share/foreman/config/initializers/active_record_extensions.rb:1:in `<top (required)>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:245:in `load'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:245:in `block in load'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:236:in `load_dependency'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/activesupport-3.2.21/lib/active_support/dependencies.rb:245:in `load'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/engine.rb:593:in `block (2 levels) in <class:Engine>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/engine.rb:592:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/engine.rb:592:in `block in <class:Engine>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:30:in `instance_exec'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:30:in `run'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:55:in `block in run_initializers'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:54:in `each'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/initializable.rb:54:in `run_initializers'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/application.rb:136:in `initialize!'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/railties-3.2.21/lib/rails/railtie/configurable.rb:30:in `method_missing'
  /usr/share/foreman/config/environment.rb:12:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.7/lib/rack/builder.rb:51:in `instance_eval'
  /usr/share/foreman/vendor/ruby/1.9.1/gems/rack-1.4.7/lib/rack/builder.rb:51:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:App>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'
domcleal commented 9 years ago

Do you have any files under /usr/share/foreman/config/hooks/?

hufman commented 9 years ago

Yes, I have a single test hook: /usr/share/foreman/config/hooks/host/destroy/30_test

#!/bin/sh

echo >> /tmp/hooklog
date >> /tmp/hooklog
echo 'Yay it ran!' $1 Host: $2 >> /tmp/hooklog
cat >> /tmp/hooklog
domcleal commented 9 years ago

Ok, move it to /usr/share/foreman/config/hooks/host/managed/destroy/30_test

hufman commented 9 years ago

Neat, that fixed it! That is a surprisingly scary error for something so minor haha! Thanks so much for the quick response!