I'm having some trouble with the following script:
require 'rubygems'
require 'active_record'
require 'net/ssh/gateway'
gateway = Net::SSH::Gateway.new('myserver.com', 'myuser', :password => "mypass")
puts "true" if gateway.active?
p = gateway.open('127.0.0.1', 3306, 3307)
class MyClass < ActiveRecord::Base
establish_connection(
:adapter => "mysql",
:host => "127.0.0.1",
:username => "db_user",
:password => "db_pass",
:database => "mydb_production",
:port => 3307
)
end
puts MyClass.all.size
gateway.shutdown!
When I run the script it just hangs, unless I remove the activerecord query. I know I can connect using tunneling because I can create a tunnel from the command like like so:
ssh -f myuser@myserver.com -L 3307/127.0.0.1/3306 -N
Then if I run:
require 'rubygems'
require 'active_record'
class MyClass < ActiveRecord::Base
establish_connection(
:adapter => "mysql",
:host => "127.0.0.1",
:username => "db_user",
:password => "db_pass",
:database => "mydb_production",
:port => 3307
)
end
puts MyClass.all.size
It works fine. What am I doing wrong?
Thanks.
I think the comment is right - the DB is conflicting with the event loop in the ssh code.
Try this:
I was able to get this to work without a fork by using the mysql2 gem