I am using net/ssh in Rails to create a tunnel through which i can connect to a remote mysql database. Since Rails never closes the connection, i have been having trouble with the tunnel timing out if there is a long period of inactivity, say more than 15 minutes. Is there any way to set up the session, or the tunnel, to send keepalive packets? Thanks, Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/net-ssh-users/attachments/20060420/028f4adf/attachment.htm
I ran into the same issue running my SSH app on standard Ruby. I had to set up a cron job to periodically send a keep alive message/command. That worked for the most part. Now, the issue I run into is data integrity. It seems that the data I get back isn''t as reliable as it should be. I''ve been trying to figure out why for months.. but so far to no avail. _____ From: net-ssh-users-bounces at rubyforge.org [mailto:net-ssh-users-bounces at rubyforge.org] On Behalf Of Lee Pope Sent: Thursday, April 20, 2006 4:37 PM To: net-ssh-users at rubyforge.org Subject: [Net-ssh-users] keepalive options? I am using net/ssh in Rails to create a tunnel through which i can connect to a remote mysql database. Since Rails never closes the connection, i have been having trouble with the tunnel timing out if there is a long period of inactivity, say more than 15 minutes. Is there any way to set up the session, or the tunnel, to send keepalive packets? Thanks, Lee -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/net-ssh-users/attachments/20060420/125a35ed/attachment.htm
It''s not always idle for that long. At times, it will have 20-50 people accessing it at the same time/short intervals. If the session had to start up every time a user accessed the page.. page load times would be around 45sec - 1min. It''s already at about 30 seconds. -----Original Message----- From: net-ssh-users-bounces at rubyforge.org [mailto:net-ssh-users-bounces at rubyforge.org] On Behalf Of zdennis Sent: Thursday, April 20, 2006 5:11 PM To: net-ssh-users at rubyforge.org Subject: Re: [Net-ssh-users] keepalive options? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Why are you keeping an SSH connection open in a rails app for 15 minutes of inactivity? This sounds like bad design... Zach Keith Duvall wrote:> > > I ran into the same issue running my SSH app on standard Ruby. I had to > set up a cron job to periodically send a keep alive message/command. > That worked for the most part. > > Now, the issue I run into is data integrity. It seems that the data I > get back isn?t as reliable as it should be. I?ve been trying to figure > out why for months.. but so far to no avail. > > > > * From: * net-ssh-users-bounces at rubyforge.org > [mailto:net-ssh-users-bounces at rubyforge.org] *On Behalf Of *Lee Pope > *Sent:* Thursday, April 20, 2006 4:37 PM > *To:* net-ssh-users at rubyforge.org > *Subject:* [Net-ssh-users] keepalive options? > > > > I am using net/ssh in Rails to create a tunnel through which i can > connect to a remote mysql database. Since Rails never closes the > connection, i have been having trouble with the tunnel timing out if > there is a long period of inactivity, say more than 15 minutes. Is there > any way to set up the session, or the tunnel, to send keepalive packets? > > Thanks, > > Lee > > > ------------------------------------------------------------------------ > > _______________________________________________ > Net-ssh-users mailing list > Net-ssh-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/net-ssh-users-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFER/jXMyx0fW1d8G0RAnJEAJ4gVxg8wffGIPaezLv8z7DZ1i2k6gCeLIlt AbbOXPbkgjNWqb4+4nsVVQg=Fun+ -----END PGP SIGNATURE----- _______________________________________________ Net-ssh-users mailing list Net-ssh-users at rubyforge.org http://rubyforge.org/mailman/listinfo/net-ssh-users
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Why are you keeping an SSH connection open in a rails app for 15 minutes of inactivity? This sounds like bad design... Zach Keith Duvall wrote:> > > I ran into the same issue running my SSH app on standard Ruby. I had to > set up a cron job to periodically send a keep alive message/command. > That worked for the most part. > > Now, the issue I run into is data integrity. It seems that the data I > get back isn?t as reliable as it should be. I?ve been trying to figure > out why for months.. but so far to no avail. > > > > * From: * net-ssh-users-bounces at rubyforge.org > [mailto:net-ssh-users-bounces at rubyforge.org] *On Behalf Of *Lee Pope > *Sent:* Thursday, April 20, 2006 4:37 PM > *To:* net-ssh-users at rubyforge.org > *Subject:* [Net-ssh-users] keepalive options? > > > > I am using net/ssh in Rails to create a tunnel through which i can > connect to a remote mysql database. Since Rails never closes the > connection, i have been having trouble with the tunnel timing out if > there is a long period of inactivity, say more than 15 minutes. Is there > any way to set up the session, or the tunnel, to send keepalive packets? > > Thanks, > > Lee > > > ------------------------------------------------------------------------ > > _______________________________________________ > Net-ssh-users mailing list > Net-ssh-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/net-ssh-users-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFER/jXMyx0fW1d8G0RAnJEAJ4gVxg8wffGIPaezLv8z7DZ1i2k6gCeLIlt AbbOXPbkgjNWqb4+4nsVVQg=Fun+ -----END PGP SIGNATURE-----
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Keith Duvall wrote:> It''s not always idle for that long. At times, it will have 20-50 people > accessing it at the same time/short intervals. If the session had to start > up every time a user accessed the page.. page load times would be around > 45sec - 1min. It''s already at about 30 seconds. >What are you doing over ssh? Perhaps sshf would be a better fit for this ? Let your OS manage the session, and not Rails.... I think it is big mistake if your dispatch.fcgi process is holding the ssh session open. I dont know exactly what is going on though, so I may be wrong. Zach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFER/w0Myx0fW1d8G0RAvBiAJ99gKE3VNEsGaSmLtD7W9VtnJOb9gCdH/Wt H+PPVabn5BDRPs18XzyqGhk=/aPq -----END PGP SIGNATURE-----
I''m not using rails. I''m running "ruby 1.8.4 (2005-12-24) [i686-linux]" I''m not familiar with sshf. Can you tell me some about it? I use SSH to log into the Cisco BTS Softswitch (The softswitch from Cisco for VoIP) and manage translations and equipment VIA a GUI interface. It also interfaces with other in-house applications to retrieve other information and perform other automated troubleshooting. The only other solution I know of to interface with the Cisco BTS, would be CORBA, which would be extremely difficult and time consuming to implement and maintain. Keith -----Original Message----- From: net-ssh-users-bounces at rubyforge.org [mailto:net-ssh-users-bounces at rubyforge.org] On Behalf Of zdennis Sent: Thursday, April 20, 2006 5:25 PM To: net-ssh-users at rubyforge.org Subject: Re: [Net-ssh-users] keepalive options? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Keith Duvall wrote:> It''s not always idle for that long. At times, it will have 20-50 people > accessing it at the same time/short intervals. If the session had to start > up every time a user accessed the page.. page load times would be around > 45sec - 1min. It''s already at about 30 seconds. >What are you doing over ssh? Perhaps sshf would be a better fit for this ? Let your OS manage the session, and not Rails.... I think it is big mistake if your dispatch.fcgi process is holding the ssh session open. I dont know exactly what is going on though, so I may be wrong. Zach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFER/w0Myx0fW1d8G0RAvBiAJ99gKE3VNEsGaSmLtD7W9VtnJOb9gCdH/Wt H+PPVabn5BDRPs18XzyqGhk=/aPq -----END PGP SIGNATURE----- _______________________________________________ Net-ssh-users mailing list Net-ssh-users at rubyforge.org http://rubyforge.org/mailman/listinfo/net-ssh-users
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Keith Duvall wrote:> I''m not using rails. > I''m running "ruby 1.8.4 (2005-12-24) [i686-linux]" > > I''m not familiar with sshf. Can you tell me some about it?I may have made an assumption that you were just trying to access a remote filesystem over ssh, hence sshfs, it''s filesystem support over ssh on *nix based machines. (my bad, i forgot an s on the end of sshf)> > I use SSH to log into the Cisco BTS Softswitch (The softswitch from Cisco > for VoIP) and manage translations and equipment VIA a GUI interface. It also > interfaces with other in-house applications to retrieve other information > and perform other automated troubleshooting. > > The only other solution I know of to interface with the Cisco BTS, would be > CORBA, which would be extremely difficult and time consuming to implement > and maintain.ah ok, i was way off the mark, as stated above, i was assuming you were using ssh to access the filesystem, not necessarily to run commands, sshfs wont work that. It sounds like you do need a persistent ssh connection to do what you are talking about. ...sorry for the scare! Zach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD4DBQFESDf6Myx0fW1d8G0RAgvTAJsFOcfYcD49tEfzrMQaBDb8GlYE0QCYgw6S VGSGZA5R+31u+fBHWnhxvg==0TPY -----END PGP SIGNATURE-----
I wish I didn''t have to use SSH. As I said before, I''ve been having allot of issues with data integrity. -----Original Message----- From: net-ssh-users-bounces at rubyforge.org [mailto:net-ssh-users-bounces at rubyforge.org] On Behalf Of zdennis Sent: Thursday, April 20, 2006 9:40 PM To: net-ssh-users at rubyforge.org Subject: Re: [Net-ssh-users] keepalive options? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Keith Duvall wrote:> I''m not using rails. > I''m running "ruby 1.8.4 (2005-12-24) [i686-linux]" > > I''m not familiar with sshf. Can you tell me some about it?I may have made an assumption that you were just trying to access a remote filesystem over ssh, hence sshfs, it''s filesystem support over ssh on *nix based machines. (my bad, i forgot an s on the end of sshf)> > I use SSH to log into the Cisco BTS Softswitch (The softswitch from Cisco > for VoIP) and manage translations and equipment VIA a GUI interface. Italso> interfaces with other in-house applications to retrieve other information > and perform other automated troubleshooting. > > The only other solution I know of to interface with the Cisco BTS, wouldbe> CORBA, which would be extremely difficult and time consuming to implement > and maintain.ah ok, i was way off the mark, as stated above, i was assuming you were using ssh to access the filesystem, not necessarily to run commands, sshfs wont work that. It sounds like you do need a persistent ssh connection to do what you are talking about. ...sorry for the scare! Zach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD4DBQFESDf6Myx0fW1d8G0RAgvTAJsFOcfYcD49tEfzrMQaBDb8GlYE0QCYgw6S VGSGZA5R+31u+fBHWnhxvg==0TPY -----END PGP SIGNATURE----- _______________________________________________ Net-ssh-users mailing list Net-ssh-users at rubyforge.org http://rubyforge.org/mailman/listinfo/net-ssh-users
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Keith Duvall wrote:> I wish I didn''t have to use SSH. As I said before, I''ve been having allot of > issues with data integrity.What kind of problems? I run Net::SSH alot for various tasks, and I use ssh like crazy. I''d be curious to hear more about the integrity issues you''re having. Are they with ssh in general or Net::SSH only? Zach -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFESDmhMyx0fW1d8G0RAvBrAJ9fWAMeG78REt9sKGXcfCPaMpal6ACdFtKu 14RDJpNWC1maOIMAMEiD90I=bjYQ -----END PGP SIGNATURE-----
They seem to be with Net::SSH only. When I get data back from the commands,
sometimes its missing lines. I know this because about every command will
have similar output. It''s all in KEY=VALUE, or KEY -> VALUE or
something
similar. I have to run allot of error checking on each commands output.
Sometimes I have to run the command 7-8 times before I get complete output.
Heres the servlet..
#//-- Beginning of servlet --\\#
#!/usr/bin/env ruby
require ''net/ssh''
require ''webrick''
require ''xmlrpc/server''
require ''pp''
user = ''user''
user_pass = ''pass''
primary = ''primary_server_ip''
secondary = ''secondary_server_ip''
startup_command = "reset password
name=#{user};new-password=#{user_pass};days-valid=364"
curr_server = primary
$pid = Process.pid
session = Net::SSH.start( curr_server, user, user_pass)
$shell = session.shell.sync(:pty => true)
sleep 1
shell_resource = Mutex.new
shell_resource.synchronize do
$myPwd = $shell.send_command("#{startup_command}\n")
end
print $myPwd.stdout
exec_servlet = XMLRPC::WEBrickServlet.new
exec_servlet.add_handler("exec_cmd") do |command|
if command.eql?("restart")
puts "Restarting Session"
session.close
session = Net::SSH.start( curr_server, user, user_pass)
$shell = session.shell.sync(:pty => true)
sleep 1
elsif command.eql?("pid")
$pid
elsif command.eql?("close")
puts "Closing Session"
session.close
else
res = {}
row = []
raw = []
raw << "raw"
mycmd = "#{command}\n"
output = nil
shell_resource.synchronize do
output = $shell.send_command(mycmd)
end
print output.stdout
output.stdout.each do |line|
raw_line = line
raw << raw_line.chomp
if line =~ /^Unable to initialize the Session/
if curr_server.eql?(primary)
curr_server = secondary
print "\n\n\nFailing Over To the secondary
server.\n\n\n"
else
curr_server = primary
print "\n\n\nFailing Over To the primary
server.\n\n\n"
end
session = Net::SSH.start( curr_server, user, user_pass)
$shell = session.shell.sync(:pty => true)
row = 2
break
elsif line.length.to_i < 3
if res.length > 0
row << res
res = {}
end
elsif line =~ /^Reply/
temp = line.split(/: /)
res[''REPLY''] = temp[1]
#puts "Rows: " << temp[2]
temp2 = /of (\d+) returned/.match(temp[2])
#pp temp2
if ! temp2.nil?
res[''ROWS''] = temp2[1]
else
res[''ROWS''] = ''NULL''
end
elsif line =~ /^CLI>/ or line =~ /^SunOS/
# do nothing
elsif line =~ /=/
temp = line.split(/=/)
blah = temp[1].chomp
res[temp[0].strip] = blah.strip
elsif line =~ /->/
temp = line.split(/ -> /)
blah = temp[1].chomp
res[temp[0].strip] = blah.strip
end
end
unless row.eql?(2)
shell_resource.synchronize do
clear_line = $shell.send_command("\n", "\n")
end
end
row << raw
row
end
end
server = WEBrick::HTTPServer.new(:Port => 9980)
trap("INT") { server.shutdown }
server.mount("/bts", exec_servlet)
server.start
#pp exec_cmd("show ndc digit_string=404\n")
#//-- End of servlet --\\#
Dunno if you can see anything.. but I''ve almost given up on finding the
problem after about 8 months of trying. :/
-----Original Message-----
From: net-ssh-users-bounces at rubyforge.org
[mailto:net-ssh-users-bounces at rubyforge.org] On Behalf Of zdennis
Sent: Thursday, April 20, 2006 9:47 PM
To: net-ssh-users at rubyforge.org
Subject: Re: [Net-ssh-users] keepalive options?
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Keith Duvall wrote:> I wish I didn''t have to use SSH. As I said before, I''ve
been having allot
of> issues with data integrity.
What kind of problems? I run Net::SSH alot for various tasks, and I use
ssh like crazy. I''d be curious to hear more about the integrity issues
you''re having.
Are they with ssh in general or Net::SSH only?
Zach
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFESDmhMyx0fW1d8G0RAvBrAJ9fWAMeG78REt9sKGXcfCPaMpal6ACdFtKu
14RDJpNWC1maOIMAMEiD90I=bjYQ
-----END PGP SIGNATURE-----
_______________________________________________
Net-ssh-users mailing list
Net-ssh-users at rubyforge.org
http://rubyforge.org/mailman/listinfo/net-ssh-users