remote_config
provides a flexible generic framework for generating the
shell commands to deploy daemons remotely.
ssh_config
generates a remote configuration for launching daemons over
SSH, with the option of SSH tunnelling.
Usage
remote_config(
command = NULL,
args = c("", "."),
rscript = "Rscript",
quote = FALSE
)
ssh_config(
remotes,
tunnel = FALSE,
timeout = 10,
command = "ssh",
rscript = "Rscript",
host
)
Arguments
- command
the command used to effect the daemon launch on the remote machine as a character string (e.g.
'ssh'
). Defaults to ‘ssh’ forssh_config
, although may be substituted for the full path to a specific SSH application. The default NULL forremote_config
does not effect any launches, but causeslaunch_remote
to return the shell commands for manual deployment on remote machines.- args
(optional) arguments passed to ‘command’, as a character vector that must include
"."
as an element, which will be substituted for the daemon launch command. Alternatively, a list of such character vectors to effect multiple launches (one for each list element).- rscript
(optional) name / path of the Rscript executable on the remote machine. The default assumes ‘Rscript’ is on the executable search path. Prepend the full path if necessary. If launching on Windows, ‘Rscript’ should be replaced with ‘Rscript.exe’.
- quote
[default FALSE] logical value whether or not to quote the daemon launch command (not required for Slurm ‘srun’ for example, but required for ‘ssh’ or Slurm ‘sbatch’).
- remotes
the character URL or vector of URLs to SSH into, using the 'ssh://' scheme and including the port open for SSH connections (defaults to 22 if not specified), e.g. 'ssh://10.75.32.90:22' or 'ssh://nodename'.
- tunnel
[default FALSE] logical value whether to use SSH reverse tunnelling. If TRUE, a tunnel is created between the same ports on the local and remote machines. See the ‘SSH Tunnelling’ section below for how to correctly specify required settings.
- timeout
[default 10] maximum time allowed for connection setup in seconds.
- host
(optional) only applicable for reverse tunnelling. Should be specified if creating a standalone configuration object. If calling this function directly as an argument to
daemons
, this is not required and can be inferred from the ‘url’ supplied (see ‘SSH Tunnelling’ section below).
Value
A list in the required format to be supplied to the ‘remote’
argument of launch_remote
, daemons
, or
make_cluster
.
SSH Direct Connections
The simplest use of SSH is to execute the daemon launch command on a remote machine, for it to dial back to the host / dispatcher URL.
It is assumed that SSH key-based authentication is already in place. The relevant port on the host must also be open to inbound connections from the remote machine.
SSH Tunnelling
Use of SSH tunnelling provides a convenient way to launch remote daemons without requiring the remote machine to be able to access the host. Often firewall configurations or security policies may prevent opening a port to accept outside connections.
In these cases SSH tunnelling offers a solution by creating a tunnel once the initial SSH connection is made. For simplicity, this SSH tunnelling implementation uses the same port on both the side of the host and that of the daemon. SSH key-based authentication must also already be in place.
Tunnelling requires the hostname for the ‘host’ argument (or the
‘url’ argument to daemons
if called directly in that
context) to be either ‘127.0.0.1’ or ‘localhost’. This is as
the tunnel is created between 127.0.0.1:port
or equivalently
localhost:port
on each machine. The host listens to port
on its
machine and the remotes each dial into port
on their own respective
machines.
Examples
# Slurm srun example
remote_config(
command = "srun",
args = c("--mem 512", "-n 1", "."),
rscript = file.path(R.home("bin"), "Rscript")
)
#> $command
#> [1] "srun"
#>
#> $args
#> [1] "--mem 512" "-n 1" "."
#>
#> $rscript
#> [1] "/opt/R/4.4.2/lib/R/bin/Rscript"
#>
#> $quote
#> [1] FALSE
#>
# Slurm sbatch requires 'quote = TRUE'
remote_config(
command = "sbatch",
args = c("--mem 512", "-n 1", "--wrap", "."),
rscript = file.path(R.home("bin"), "Rscript"),
quote = TRUE
)
#> $command
#> [1] "sbatch"
#>
#> $args
#> [1] "--mem 512" "-n 1" "--wrap" "."
#>
#> $rscript
#> [1] "/opt/R/4.4.2/lib/R/bin/Rscript"
#>
#> $quote
#> [1] TRUE
#>
# SSH also requires 'quote = TRUE'
remote_config(
command = "/usr/bin/ssh",
args = c("-fTp 22 10.75.32.90", "."),
quote = TRUE
)
#> $command
#> [1] "/usr/bin/ssh"
#>
#> $args
#> [1] "-fTp 22 10.75.32.90" "."
#>
#> $rscript
#> [1] "Rscript"
#>
#> $quote
#> [1] TRUE
#>
# can be used to start local dameons with special configurations
remote_config(
command = "Rscript",
rscript = "--default-packages=NULL --vanilla"
)
#> $command
#> [1] "Rscript"
#>
#> $args
#> [1] "" "."
#>
#> $rscript
#> [1] "--default-packages=NULL --vanilla"
#>
#> $quote
#> [1] FALSE
#>
# simple SSH example
ssh_config(
remotes = c("ssh://10.75.32.90:222", "ssh://nodename"),
timeout = 5
)
#> $command
#> [1] "ssh"
#>
#> $args
#> $args[[1]]
#> [1] "-o ConnectTimeout=5 -fTp 222" "10.75.32.90"
#> [3] "."
#>
#> $args[[2]]
#> [1] "-o ConnectTimeout=5 -fTp 22" "nodename"
#> [3] "."
#>
#>
#> $rscript
#> [1] "Rscript"
#>
#> $quote
#> [1] TRUE
#>
# SSH tunnelling example
ssh_config(
remotes = c("ssh://10.75.32.90:222", "ssh://nodename"),
tunnel = TRUE,
host = "tls+tcp://127.0.0.1:5555"
)
#> $command
#> [1] "ssh"
#>
#> $args
#> $args[[1]]
#> [1] "-R 5555:127.0.0.1:5555" "-o ConnectTimeout=10 -fTp 222"
#> [3] "10.75.32.90" "."
#>
#> $args[[2]]
#> [1] "-R 5555:127.0.0.1:5555" "-o ConnectTimeout=10 -fTp 22"
#> [3] "nodename" "."
#>
#>
#> $rscript
#> [1] "Rscript"
#>
#> $quote
#> [1] TRUE
#>
if (FALSE) { # \dontrun{
# launch 2 daemons on the remote machines 10.75.32.90 and 10.75.32.91 using
# SSH, connecting back directly to the host URL over a TLS connection:
daemons(
url = host_url(tls = TRUE),
remote = ssh_config(
remotes = c("ssh://10.75.32.90:222", "ssh://10.75.32.91:222"),
timeout = 1
)
)
# launch 2 nodes on the remote machine 10.75.32.90 using SSH tunnelling over
# port 5555 ('url' hostname must be 'localhost' or '127.0.0.1'):
cl <- make_cluster(
url = "tcp://localhost:5555",
remote = ssh_config(
remotes = c("ssh://10.75.32.90", "ssh://10.75.32.90"),
tunnel = TRUE,
timeout = 1
)
)
} # }