From b8d4a39288cba960339ca07ef92df2aab1a7559b Mon Sep 17 00:00:00 2001 From: Michael Schubert Date: Sat, 16 Dec 2023 22:30:57 +0100 Subject: [PATCH] allow customization of ssh fwd port (fixes #296) --- R/qsys_ssh.r | 11 +++++------ inst/SSH.tmpl | 4 ++-- vignettes/userguide.Rmd | 3 +++ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/R/qsys_ssh.r b/R/qsys_ssh.r index 4486238..1577a3e 100644 --- a/R/qsys_ssh.r +++ b/R/qsys_ssh.r @@ -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))) @@ -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) { diff --git a/inst/SSH.tmpl b/inst/SSH.tmpl index 56a83a4..0cbfe34 100644 --- a/inst/SSH.tmpl +++ b/inst/SSH.tmpl @@ -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" diff --git a/vignettes/userguide.Rmd b/vignettes/userguide.Rmd index cddfceb..db651bb 100644 --- a/vignettes/userguide.Rmd +++ b/vignettes/userguide.Rmd @@ -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)