ControlNode.Host.SSH (Control Node v0.2.0) View Source

Link to this section Summary

Types

t()

SSH spec defines a host which shall be used to connect and deploy releases. Following fields should be defined

Functions

Connect to SSH host

Closes SSH connection to remote host

Execute a given list of command or a bash script on the host VM

Establishes SSH tunnel on given port i.e. tunnel from localhost:port to remote_host:port.

Establishes SSH tunnel on from localhost:local_port to remote_host:remote_port

Uploads tar_file to the host server via SSH and stores it at file_path on the remote server.

Link to this section Types

Specs

t() :: %ControlNode.Host.SSH{
  conn: :ssh.connection_ref(),
  epmd_port: integer(),
  host: binary(),
  hostname: binary(),
  port: integer(),
  private_key_dir: binary(),
  user: binary(),
  via_ssh_agent: boolean()
}

SSH spec defines a host which shall be used to connect and deploy releases. Following fields should be defined

  • :host : Remote host uri (eg. server1.somehost.com)
  • :port : SSH port for connecting to the server (default 22)
  • :epmd_port : Port where EPMD is expected to be running on host (default 4369)
  • :user : SSH user name
  • :private_key_dir : Path to the .ssh folder (eg. /home/user/.ssh)
  • via_ssh_agent: Use SSH Agent for authentication (default false)

Link to this section Functions

Specs

connect(t()) :: t()

Connect to SSH host

Closes SSH connection to remote host

Link to this function

exec(ssh_config, commands, skip_eof \\ false)

View Source

Execute a given list of command or a bash script on the host VM

skip_eof : For commands which start long running processes skip_eof should be set to true. This enable exec to return ExecStatus while the command is left running on host.

Link to this function

tunnel_port_to_server(ssh_config, port)

View Source

Specs

tunnel_port_to_server(t(), :inet.port_number()) ::
  {:ok, :inet.port_number()} | {:error, any()}

Establishes SSH tunnel on given port i.e. tunnel from localhost:port to remote_host:port.

ssh_config defines the remote host

Link to this function

tunnel_port_to_server(ssh_config, local_port, remote_port)

View Source

Specs

tunnel_port_to_server(t(), :inet.port_number(), :inet.port_number()) ::
  {:ok, :inet.port_number()} | {:error, any()}

Establishes SSH tunnel on from localhost:local_port to remote_host:remote_port

ssh_config defines the remote host

Link to this function

upload_file(ssh_config, file_path, tar_file)

View Source

Specs

upload_file(t(), binary(), binary()) :: :ok

Uploads tar_file to the host server via SSH and stores it at file_path on the remote server.

file_path should be absolute path on the remote server. file_path is created recursively in case it doesn't exist.

Example

iex> ssh_config = %SSH{host: "remote-host.com", port: 22, user: "username", private_key_dir: "/home/local_user/.ssh"}
iex> ControlNode.Host.SSH.upload_file(ssh_config, "/opt/remote/server/directory", "file_contexts_binary")
:ok