Bug 1121002

Summary: [origin_cartridge_229]Failed to access mysql via DB driver for ruby-2.0 app
Product: OpenShift Online Reporter: Lei Zhang <lzhang>
Component: ImageAssignee: Michal Fojtik <mfojtik>
Status: CLOSED UPSTREAM QA Contact: libra bugs <libra-bugs>
Severity: medium Docs Contact:
Priority: medium    
Version: 2.xCC: jokerman, mfojtik, mmccomas, tdawson, xtian
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2014-07-21 14:37:13 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
config.ru
none
mysql_factory.rb none

Description Lei Zhang 2014-07-18 06:21:07 UTC
Description of problem:
Create one ruby-2.0 app, embed mysql-5.1/5.5 db, add related db access files and git push, try to access http://$appname-$domainname-dev.rhcloud.com/mysql, found 500 error. login the app via rhcsh and check app-root/logs/ruby.log, found `require': cannot load such file -- mysql (LoadError)


[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr] /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require': cannot load such file -- mysql (LoadError)
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /var/lib/openshift/53c8e9912afe6a471d000398/app-root/runtime/repo/mysql_factory.rb:2:in `<top (required)>'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ruby200/root/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:53:in `require'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from config.ru:18:in `block (3 levels) in <main>'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ror40/root/usr/share/gems/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ror40/root/usr/share/gems/gems/rack-1.5.2/lib/rack/builder.rb:138:in `call'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ror40/root/usr/share/gems/gems/rack-1.5.2/lib/rack/urlmap.rb:65:in `block in call'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ror40/root/usr/share/gems/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `each'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ror40/root/usr/share/gems/gems/rack-1.5.2/lib/rack/urlmap.rb:50:in `call'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ruby200/root/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/rack/thread_handler_extension.rb:77:in `process_request'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ruby200/root/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:140:in `accept_and_process_next_request'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ruby200/root/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/request_handler/thread_handler.rb:108:in `main_loop'
[ 2014-07-18 05:34:43.5498 2400/7f2dfc7ed700 Pool2/Implementation.cpp:1274 ]: [App 2553 stderr]     from /opt/rh/ruby200/root/usr/share/gems/gems/passenger-4.0.18/lib/phusion_passenger/request_handler.rb:441:in `block (3 levels) in start_threads'

Version-Release number of selected component (if applicable):
devenv-4978

How reproducible:
always

Steps to Reproduce:
1.create ruby-2.0 app and embed with mysql-5.5 db cartridge
#rhc app create myruby20 ruby-2.0 mysql-5.5
2.add related db accessing file and git push
add mysql_factory.rb and config.ru to local repo (pls refer to attachment) 
#git add .&& git commit -amp&&git push
3.try to access http://$appname-$domainname-dev.rhcloud.com/mysql

Actual results:
Failed to access mysql via db driver

Expected results:
Can access mysql via db driver

Additional info:
If login in the app via rhcsh, 'gem install mysql' and restart the app, can access mysql via db driver from website. 

[myruby20-hlhplw.dev.rhcloud.com 53c8e9912afe6a471d000398]\> gem install mysql
Fetching: mysql-2.9.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed mysql-2.9.1
1 gem installed

[lijun@ray myruby20]$ curl -k  https://myruby20-hlhplw.dev.rhcloud.com/mysql
version 1

Comment 1 Lei Zhang 2014-07-18 06:24:40 UTC
Created attachment 918975 [details]
config.ru

Comment 2 Lei Zhang 2014-07-18 06:25:20 UTC
Created attachment 918976 [details]
mysql_factory.rb

Comment 3 Michal Fojtik 2014-07-18 11:39:09 UTC
Lei, try to use the 'mysql2' gem instead of 'mysql', but I'm going to reproduce it on devenv.

Comment 4 Lei Zhang 2014-07-21 03:32:00 UTC
Hi Michal, I updated require 'mysql2'" into the mysql_factory.rb file and "gem install mysql2 in the app, when access mysql via curl after restart, failed to access it. 

[lijun@ray shcknafm]$ head -n 3 mysql_factory.rb 
#!/usr/bin/env ruby
require 'mysql2'

[lijun@ray shcknafm]$ rhc app ssh shcknafm "gem list mysql"
mysql2 (0.3.16)
[lijun@ray shcknafm]$ curl http://shcknafm-retokl.dev.rhcloud.com/mysql
uninitialized constant MySQL::Mysql 

But, if I used require 'mysql'" in the mysql_factory.rb file and "gem install mysql in the app, when access mysql via curl after restart the app, can access it.

[lijun@ray shcknafm]$ head -n 3 mysql_factory.rb 
#!/usr/bin/env ruby
require 'mysql'

[lijun@ray shcknafm]$ rhc app ssh shcknafm "gem list mysql"
mysql (2.9.1)

[lijun@ray shcknafm]$ curl http://shcknafm-retokl.dev.rhcloud.com/mysql
version 1

Comment 5 Michal Fojtik 2014-07-21 10:28:45 UTC
Lei: OK I figured out now, that this is a missing RPM problem. We don't have mysql2/mysql rpms for the ruby20 so for that you have to install them manually.

But we think that 99% of our users will use Bundler and put them into Gemfile (so they will install those manually, via bunder).

I'm tempted to close this as a WONTFIX, but I contacted Troy to see how much effort it will be to add those RPMS.

Comment 7 Troy Dawson 2014-09-04 13:32:35 UTC
Info provided offline.  Removing needinfo.