nodex v0.1.2 Nodex.Distributed
A module to help setting up a distributed environment.
Examples
Starting and stopping a distributed environment:
iex> Node.alive?
false
iex> Nodex.Distributed.up
iex> Node.alive?
true
iex> Nodex.Distributed.down
iex> Node.alive?
false
Spawning 2 new slaves:
iex> Nodex.Distributed.up
iex> Nodex.Distributed.spawn_slaves(2)
[:"slave1@127.0.0.1", :"slave2@127.0.0.1"]
Loading a dynamically defined module onto a remote node and call a function on it remotely:
iex> Nodex.Distributed.up
iex> [node] = Nodex.Distributed.spawn_slaves(1)
iex> {:module, module, object_code, _} = defmodule A, do: def greet, do: "hi from " <> to_string(Node.self)
iex> Nodex.Distributed.rpc(node, A, :greet, []) # this won't work, A is not present on the remote node
iex> Nodex.Distributed.load_object_code(node, module, object_code)
iex> Nodex.Distributed.rpc(node, A, :greet, [])
{:ok, "hi from slave1@127.0.0.1"}
Link to this section Summary
Functions
Stops the distributed environment and all slaves.
Load the given module on the remote node.
Load the given object code into module, file on the remote node.
Remote procedure call on the given remote node.
Remote procedure call on the given remote node. Raise on badrpc.
Starts :net_kernel
, :erl_boot_server
.
List all nodes that have been started by Nodex.Distributed
.
Start an instance of the erlang port mapper daemon.
Spawn a slave.
Spawn a number of new slaves.
Starts a distributed environment.
Link to this section Functions
down()
Specs
down() :: :ok
Stops the distributed environment and all slaves.
Stops :net_kernel
and calls :slave.stop/1
on all connected nodes.
It will spawn an instance of epmd (Erlang Port Mapper Daemon) and start :net_kernel
.
load_module(node, module)
Specs
Load the given module on the remote node.
load_object_code(node, module, object_code)
Specs
Load the given object code into module, file on the remote node.
Just a wrapper to call :code.load_binary/3
remotely.
rpc(node, module, function, args)
Specs
Remote procedure call on the given remote node.
rpc!(node, module, function, args)
Specs
Remote procedure call on the given remote node. Raise on badrpc.
setup_master(master_sname \\ "master", ip \\ "127.0.0.1")
Specs
Starts :net_kernel
, :erl_boot_server
.
Adds the ip as a slave node to the list of allowed slave hosts.
Optionally accepts an sname
and ip
as argument.
Parameters
sname
: Provide a short name for this node. (default:"master"
)ip
: Provide an ip address for this node. (default:"127.0.0.1"
)
slaves()
Specs
slaves() :: [node()]
List all nodes that have been started by Nodex.Distributed
.
Does not list other nodes connected to this node.
For a list of all connected nodes use Node.list/0
, or Node.list/1
.
spawn_epmd()
Specs
Start an instance of the erlang port mapper daemon.
It looks for the epmd
executable using System.find_executable/1
(that looks into the PATH
environment variable).
Note, that epmd just exits if another instance of it is already running on the same host.
spawn_slave(node)
Specs
Spawn a slave.
Add all code paths from this node, transfer elixir configuration and ensure all applications are started like on this node.
spawn_slaves(num_nodes, ip \\ "127.0.0.1")
Specs
Spawn a number of new slaves.
Optionally accepts an ip
as argument.
Slaves are named "slave<index>", index starts at 1. Starting 2 slaves, starts two new nodes slave1@127.0.0.1
and slave2@127.0.0.1
See spawn_slave/1
for a description of what is loaded on the newly spawned node.
Returns a list of node identifiers that have been started.
up(master_sname \\ "master", ip \\ "127.0.0.1")
Specs
Starts a distributed environment.
It will spawn an instance of epmd (Erlang Port Mapper Daemon) and start :net_kernel
.
Optionally accepts an sname
and ip
as argument.
Parameters
sname
: Provide a short name for this node. (default:"master"
)ip
: Provide an ip this node should be listening on. (default:"127.0.0.1"
)