Module otpbp_peer

Controller for additional Erlang node running on the same host, or in a different container/host (e.g.

Behaviours: gen_server.

Description

Controller for additional Erlang node running on the same host, or in a different container/host (e.g. Docker).

Terms

Origin node - Erlang VM instance that spawns additional nodes. Peer node - a node spawned by the origin. Control process - a process running on origin node, if it terminates, peer node terminates too. Control connection - a connection between origin and peer, can be ether Erlang Distribution connection, or alternative one.

I/O is forwarded from peer node to origin via control connection.

When standard_io is used as alternative connection, peer node uses standard out to multiplex console output and control sequences. Characters in range of 192-255 are reserved for control sequences, see encode_port_data for details. If peer node attempts to print characters in this range, an controlling process on the origin node may terminate with an error (because CRC check will fail).

Alternative connection via TCP does not have that limitation, but it also does not redirect console I/O from the peer node.

Data Types

connection()

connection() = 0..65535 | {inet:ip_address(), 0..65535} | standard_io

disconnect_timeout()

disconnect_timeout() = 1000..4294967295 | infinity

exec()

exec() = file:name() | {file:name(), [string()]}

SSH support: {"/usr/bin/ssh", ["account@host_b", "/usr/bin/erl"]}

peer_state()

peer_state() = booting | running | {down, Reason::term()}

server_ref()

server_ref() = pid()

start_options()

start_options() = #{name => atom() | string(), longnames => boolean(), host => string(), peer_down => stop | continue | crash, connection => connection(), exec => exec(), detached => boolean(), args => [string()], post_process_args => fun(([string()]) -> [string()]), env => [{string(), string()}], wait_boot => wait_boot(), shutdown => close | halt | {halt, disconnect_timeout()} | disconnect_timeout()}

state()

state() = #peer_state{options = start_options(), node = atom(), exec = file:name(), args = [string()], connection = undefined | port() | gen_tcp:socket(), listen_socket = undefined | gen_tcp:socket(), stdio = binary(), peer_state = peer_state(), notify = false | {pid(), reference()}, seq = non_neg_integer(), outstanding = #{non_neg_integer() => {reference(), pid()}}}

wait_boot()

wait_boot() = timeout() | {pid(), Tag::term()} | false

Function Index

call/4Calls M:F(A) remotely, via alternative connection, with default 5 seconds timeout.
call/5Call M:F(A) remotely, timeout is explicitly specified.
cast/4Cast M:F(A) remotely, don't care about the result.
code_change/3
get_state/1returns peer node state.
handle_call/3
handle_cast/2
handle_info/2
init/1
init_supervision/2
random_name/0Creates random node name, using "peer" as prefix.
random_name/1Creates sufficiently random node name, using OS process ID for origin VM, resulting name looks like prefix-3-7161.
send/3Sends a message to pid or named process on the peer node using alternative connection.
start/0
start/1Starts peer node, not linked to the calling process.
start_link/0Starts a distributed node with random name, on this host, and waits for that node to boot.
start_link/1Starts peer node, linked to the calling process.
start_supervision/0
stop/1Stops controlling process, shutting down peer node synchronously.
supervision_child_spec/0
system_code_change/4
system_continue/3
system_get_state/1
system_replace_state/2
system_terminate/4
terminate/2

Function Details

call/4

call(Dest::server_ref(), Module::module(), Function::atom(), Args::[term()]) -> Result::term()

Calls M:F(A) remotely, via alternative connection, with default 5 seconds timeout

call/5

call(Dest::server_ref(), Module::module(), Function::atom(), Args::[term()], Timeout::timeout()) -> Result::term()

Call M:F(A) remotely, timeout is explicitly specified

cast/4

cast(Dest::server_ref(), Module::module(), Function::atom(), Args::[term()]) -> ok

Cast M:F(A) remotely, don't care about the result

code_change/3

code_change(OldVsn, State, Extra) -> any()

get_state/1

get_state(Dest::server_ref()) -> peer_state()

returns peer node state.

handle_call/3

handle_call(X1, From, Peer_state) -> any()

handle_cast/2

handle_cast(X1, Peer_state) -> any()

handle_info/2

handle_info(X1, Peer_state) -> any()

init/1

init(X1::[Name::atom(), ...]) -> {ok, state()}

init_supervision/2

init_supervision(Parent::term(), InSupTree::term()) -> no_return()

random_name/0

random_name() -> string()

Creates random node name, using "peer" as prefix.

random_name/1

random_name(Prefix::string() | atom()) -> string()

Creates sufficiently random node name, using OS process ID for origin VM, resulting name looks like prefix-3-7161

send/3

send(Dest::server_ref(), To::pid() | atom(), Message::term()) -> ok

Sends a message to pid or named process on the peer node using alternative connection. No delivery guarantee.

start/0

start() -> pid()

start/1

start(Options::start_options()) -> {ok, pid()} | {ok, pid(), node()} | {error, Reason}

Starts peer node, not linked to the calling process.

start_link/0

start_link() -> {ok, pid(), node()} | {error, Reason::term()}

Starts a distributed node with random name, on this host, and waits for that node to boot. Returns full node name, registers local process with the same name as peer node.

start_link/1

start_link(Options::start_options()) -> {ok, pid()} | {ok, pid(), node()} | {error, Reason}

Starts peer node, linked to the calling process. Accepts additional command line arguments and other important options.

start_supervision/0

start_supervision() -> any()

stop/1

stop(Dest::server_ref()) -> ok

Stops controlling process, shutting down peer node synchronously

supervision_child_spec/0

supervision_child_spec() -> any()

system_code_change/4

system_code_change(State, Module, OldVsn, Extra) -> any()

system_continue/3

system_continue(Parent, X2, Peer_sup_state) -> any()

system_get_state/1

system_get_state(State) -> any()

system_replace_state/2

system_replace_state(StateFun, State) -> any()

system_terminate/4

system_terminate(Reason, Parent, Debug, State) -> any()

terminate/2

terminate(Reason::term(), Peer_state::state()) -> ok


Generated by EDoc