Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

mod_perl persistent SSH connections

by saberworks (Curate)
on Jan 11, 2011 at 23:31 UTC ( #881782=perlquestion: print w/replies, xml ) Need Help??

saberworks has asked for the wisdom of the Perl Monks concerning the following question:

My question is similar in spirit to Creating Socket Connections that are persistent across multiple page loads in a single web session. I need to keep certain objects alive and well between requests to a mod_perl program. As unlinker mentioned in his last comment on that thread, I also need to keep the pool of persistent objects global (one pool total, not one pool per apache process or apache thread). In my case it will be ssh connection objects. Is there a way to keep a global cache?

My understanding of POE and the like is that it can run as a separate process on the web server and my mod_perl code can possible talk to it. However, it seems like I won't be able to actually pass active Net::SSH objects or similar back and forth between separate programs. I could potentially have all interaction with the Net::SSH objects happen on the POE side but I would appreciate suggestions on how to structure this so that my mod_perl program can talk to the POE program to get the correct POE child/thread/process and then talk to that directly.

Essentially, I will have a number of users connecting to apache which will be running mod_perl. These users would be indirectly interacting with remote SSH connections that need to be pooled on the server side and must be persistent so the users' current ssh sessions don't get disconnected/lost/overwritten between requests.

Replies are listed 'Best First'.
Re: mod_perl persistent SSH connections
by salva (Canon) on Jan 12, 2011 at 08:54 UTC
    Net::SSH establishes a new SSH connection for every command it has to run. If you want to reuse connections, you will have to use some other module as Net::SSH2, Net::OpenSSH or Net::SSH::Perl.

    Even then, these modules will by default create a new session for every command run. If you want to keep the sessions open you will have to run a shell and talk to it through its STDIN/STDOUT channels. Expect may be useful for that (or Net::SSH::Expect).

Re: mod_perl persistent SSH connections
by Anonyrnous Monk (Hermit) on Jan 12, 2011 at 00:07 UTC

    Maybe the respective apache child could connect to the persistent ssh via sockets (e.g. unix domain sockets)?

    I.e., the user's session would hold a number which corresponds to the ssh/socket that was initially started for the user. The socket would then simply serve to forward the stdin/stdout pipes of the ssh being run in a separate process...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://881782]
Approved by ww
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (2)
As of 2021-02-25 00:04 GMT
Find Nodes?
    Voting Booth?

    No recent polls found