juanje / cookbook-redmine

Chef's Cookbook for installing Redmine
25 stars 21 forks source link

Set value of local variable "adapter" in recipes/source.rb to "mysql" if it equals "mysql2" #11

Open pbchase opened 11 years ago

pbchase commented 11 years ago

In some contexts the attribute node["redmine"]["databases"][environment]["adapter"] refers to a gem name. As such it can assume value of "mysql" or "mysql2" among others. However, in recipes/sources.rb the adapter variable is used repeatedly in case statements that do not support the value "mysql2".

This is the error log received when node["redmine"]["databases"][environment]["adapter"] == "mysql2"

================================================================================

Recipe Compile Error in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/redmine/recipes/default.rb

================================================================================

NoMethodError

-------------

undefined method `each' for nil:NilClass

Cookbook Trace:

---------------

  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/redmine/recipes/source.rb:50:in `from_file'
  /tmp/vagrant-chef-1/chef-solo-1/cookbooks/redmine/recipes/default.rb:27:in `from_file'

Relevant File Content:
----------------------
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/redmine/recipes/source.rb:

 43:  if node['redmine']['install_rmagick']
 44:    node['redmine']['packages']['rmagick'].each do |pkg|
 45:      package pkg
 46:    end
 47:  end
 48:  
 49:  #Setup database
 50>> node['redmine']['packages'][adapter].each do |pkg|
 51:    package pkg
 52:  end
 53:  case adapter
 54:  when "mysql"
 55:    include_recipe "mysql::server"
 56:    include_recipe "database::mysql"
 57:  when "postgresql"
 58:    include_recipe "postgresql::server"
 59:    include_recipe "database::postgresql"

[2013-05-23T17:14:19+00:00] ERROR: Running exception handlers
[2013-05-23T17:14:19+00:00] ERROR: Exception handlers complete
[2013-05-23T17:14:19+00:00] FATAL: Stacktrace dumped to /tmp/vagrant-chef-1/chef-stacktrace.out
[2013-05-23T17:14:19+00:00] FATAL: NoMethodError: undefined method `each' for nil:NilClass
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.

Rewriting the value of adapter from "mysql2" to "mysql" within recipes/sources.rb allows the existing case statements to select mysql components.

Platform tested: Debian 7 RC1 64-bit Version tested: Chef: 11.4.0 Cookbook versions:

juanje commented 11 years ago

Hi @pbchase,

Actually, the only adapter supported (for Mysql) is mysql. The adapter is not the gem name in this case. The only place where is used the gem's name mysql2 is at the database template.

Maybe it should be more clear at the documentation that the supported adapter are just mysql and postgresql, and that the mysql gem's name will depend on the Ruby's version.

I don't know if this resolve your issue of you still see something that need to be done about this PR.

Thanks for the feedback :smile:

pbchase commented 11 years ago

So when is the mysql gem installed? I tried it your way, had some errors I had to stumble through, but ultimately received a complaint from passenger the mysql2 gem could not be found.

This is, by the way, with Redmine 2.3.1.

Ruby (Rack) application could not be started
These are the possible causes:
There may be a syntax error in the application's code. Please check for such errors and fix them.
A required library may not installed. Please install all libraries that this application requires.
The application may not be properly configured. Please check whether all configuration files are written correctly, fix any incorrect configurations, and restart this application.
A service that the application relies on (such as the database server or the Ferret search engine server) may not have been started. Please start that service.
Further information about the error may have been written to the application's log file. Please check it in order to analyse the problem.
Error message:
Could not find gem 'mysql2 (~> 0.3.11) ruby' in the gems available on this machine. (Bundler::GemNotFound)
Exception class:
PhusionPassenger::UnknownError
Application root:
/var/www/redmine
Backtrace:
#   File    Line    Location
0   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/resolver.rb 296 in `resolve'
1   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/resolver.rb 168 in `start'
2   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/resolver.rb 129 in `block in resolve'
3   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/resolver.rb 128 in `catch'
4   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/resolver.rb 128 in `resolve'
5   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/definition.rb   179 in `resolve'
6   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/definition.rb   114 in `specs'
7   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/definition.rb   159 in `specs_for'
8   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/definition.rb   148 in `requested_specs'
9   /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/environment.rb  18  in `requested_specs'
10  /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb  13  in `setup'
11  /usr/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler.rb  120 in `setup'
12  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/utils.rb   326 in `prepare_app_process'
13  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/rack/application_spawner.rb    156 in `block in initialize_server'
14  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/utils.rb   563 in `report_app_init_status'
15  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/rack/application_spawner.rb    154 in `initialize_server'
16  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb 204 in `start_synchronously'
17  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb 180 in `start'
18  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/rack/application_spawner.rb    129 in `start'
19  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb   253 in `block (2 levels) in spawn_rack_application'
20  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server_collection.rb  132 in `lookup_or_add'
21  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb   246 in `block in spawn_rack_application'
22  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server_collection.rb  82  in `block in synchronize'
23      prelude>    10:in `synchronize'
24  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server_collection.rb  79  in `synchronize'
25  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb   244 in `spawn_rack_application'
26  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb   137 in `spawn_application'
27  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/spawn_manager.rb   275 in `handle_spawn_application'
28  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb 357 in `server_main_loop'
29  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/lib/phusion_passenger/abstract_server.rb 206 in `start_synchronously'
30  /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.19/helper-scripts/passenger-spawn-server    99  in `
'
juanje commented 11 years ago

Hi, @pbchase, sorry for the delay.

I've to check this properly, because I have the minimal tests passed on CentOS and Ubuntu, but I didn't try in Debian nor I did dig too much into the passender part.

One question. Did you run by hand the Redmine application or was was Chef?

I've checked a bit the logs and a vagrant box with the recipe installed and the problem could come from the Ruby paths. Chef uses a different path (I believe) than the system and I think the gem may be installed in the Chef's path.

Any feedback will be much appreciated.

Thanks for the help :smile: