Skip to content

Commit

Permalink
allow customization of ssh fwd port (fixes #296)
Browse files Browse the repository at this point in the history
  • Loading branch information
mschubert committed Dec 16, 2023
1 parent dad2f5d commit b8d4a39
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
11 changes: 5 additions & 6 deletions R/qsys_ssh.r
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ SSH = R6::R6Class("SSH",
# set forward and run ssh.r (send port, master)
opts = private$fill_options(ssh_log=ssh_log, ssh_host=ssh_host)
ssh_cmd = fill_template(private$template, opts,
required=c("local_port", "remote_port", "ssh_host"))
required=c("local_port", "ssh.hpc_fwd_port", "ssh_host"))

# wait for ssh to connect
message(sprintf("Connecting to %s via SSH ...", sQuote(ssh_host)))
Expand Down Expand Up @@ -52,11 +52,10 @@ SSH = R6::R6Class("SSH",
ssh_proxy_running = TRUE,

fill_options = function(...) {
values = utils::modifyList(private$defaults, list(...))
#TODO: let user define ports in private$defaults here and respect them
values$local_port = sub(".*:", "", private$addr)
values$remote_port = sample(50000:55000, 1)
values
args = list(...)
args$local_port = sub(".*:", "", private$addr)
args$ssh.hpc_fwd_port = getOption("clustermq.ssh.hpc_fwd_port", sample(50000:55000, 1))
utils::modifyList(private$defaults, args)
},

finalize = function(quiet = self$workers_running == 0) {
Expand Down
4 changes: 2 additions & 2 deletions inst/SSH.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ssh -o "ExitOnForwardFailure yes" -f
-R {{ remote_port }}:127.0.0.1:{{ local_port }}
-R {{ ssh.hpc_fwd_port }}:127.0.0.1:{{ local_port }}
{{ ssh_host }}
"R --no-save --no-restore -e
'clustermq:::ssh_proxy({{ remote_port }})'
'clustermq:::ssh_proxy({{ ssh.hpc_fwd_port }})'
> {{ ssh_log | /dev/null }} 2>&1"
3 changes: 3 additions & 0 deletions vignettes/userguide.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ time after you restart R.
(e.g. `"~/cmq_ssh.log"`); helpful for debugging purposes
* `clustermq.ssh.timeout` - The amount of time to wait (in seconds) for a SSH
start-up connection before timing out (default is `10` seconds)
* `clustermq.ssh.hpc_fwd_port` - Port that will be opened for SSH reverse
tunneling between the workers on the HPC and a local session
(default: one integer in the range of 50-55k)
* `clustermq.worker.timeout` - The amount of time to wait (in seconds) for
master-worker communication before timing out (default is to wait
indefinitely)
Expand Down

0 comments on commit b8d4a39

Please sign in to comment.