Comments (1)
You can try something like.
start_tunnel_process <- function(user, server, port, stderr = nullfile()) {
proc <- callr::r_bg(
function(user, server, port) {
ssh_host <- paste(user, server, sep = "@")
while (TRUE) {
ssh_session <- ssh::ssh_connect(ssh_host, keyfile = "~/.ssh/id_rsa", verbose = FALSE)
ssh::ssh_tunnel(ssh_session, port = port, target = "localhost:27017")
ssh::ssh_disconnect(ssh_session)
}
},
args = list(user, server, port),
stdout = nullfile(),
stderr = stderr
)
proc
}
I currently evaluating this for my use case with mongolite.
url <- sprintf("mongodb://%s:%s@%s:%s", user, password, host, as.integer(port))
con <- mongo(collection, db = database, url = url)
con$find()
con$disconnect()
You need the while loop since after you disconnect the tunnel will close.
The while will create a new tunnel. This also means it will fail, if the time between two connections is to short for the 2nd process to create a new tunnel. You can hack this by putting a fault tolerant loop around your connect function.
for (i in seq_len(100)) {
status <- try(con <- mongo(collection, db = database, url = url), silent = TRUE)
if (!inherits(status, "try-error")) break
Sys.sleep(0.2)
}
This works, but is also kind of a hack since the background R process runs at 100% CPU all the time which is to much.
from ssh.
Related Issues (20)
- problem using scp on a complete folder tree
- Package installation onto Docker HOT 1
- SSH failing to open Known host file HOT 1
- ssh_tunnel to localhost.run
- Error when using scp_upload() & scp_download on some SFTPs
- SSH session automatically disconnects after parallel programming
- cannot scp_upload from Windows to Windows HOT 1
- cannot use wildcards with scp_download
- Problems wit large files with scp_download
- switch user using sudo failing HOT 1
- ssh-agent not being found HOT 1
- Feature Request: `ssh_info()` works on disconnected sessions
- SSH_AUTH_METHOD_PASSWORD does not seem to be working
- scp_upload problem in newest verision HOT 1
- Could add function support SSH without password HOT 1
- How do I preserve the mode permission of a file with scp_upload HOT 1
- scp_upload and scp_download fail for UNC paths without permission on root directory
- Uploading large files using scp_upload() causes RStudio session crash
- Unable to connect from windows due to algorithm mismatch HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ssh.