Bercovici Adrian
Bercovici Adrian

Reputation: 9360

How to run an application distributed using Rebar?

I have an application that I want to run distributed on two nodes (one main and one failover).

I have two config files for each node.
Now I am running my application on the two nodes using:

rebar3 shell --sname a --config a 
rebar3 shell --sname b --config b

The problem is that the application starts on both nodes since I suppose they are not pre-connected when I am issuing the rebar command.

Config files

[
    {kernel,[{distributed,[{ex_banking,['a@AdrianB-LAPTOP','b@Adrian-LAPTOP']}]},
             {sync_nodes_timeout,3000}]},
    {ex_banking,[{port,3000}]}].
[
    {kernel,[{distributed,[{ex_banking,['a@AdrianB-LAPTOP','b@Adrian-LAPTOP']}]},
             {sync_nodes_mandatory,['a@AdrianB-LAPTOP'},
             {sync_nodes_timeout,3000}]},
    {ex_banking,[{port,3000}]}].

What is the strategy to connect the nodes when/after using rebar shell? Is there any way to create scripts or something?

I just want the nodes connected but only the main one starting witht the application started,while the second one takes on when the first crashes.

Upvotes: 2

Views: 690

Answers (1)

vkatsuba
vkatsuba

Reputation: 1449

To connect two or more nodes, you need also set same cookies for each node. And then ping those nodes by net_adm:ping/1. Here is example(expected that terminals will start at the same time ):

Terminal #1:

$ ./rebar3 shell --sname a --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V12.1.5  (abort with ^G)
(a@pc)1> nodes().
[]

Terminal #2:

$ ./rebar3 shell --sname b --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V12.1.5  (abort with ^G)
(b@pc)1> nodes().
[]

As you see, when you run it - we don't have any nodes. Now lets try use net_adm:ping/1 to connect them. Terminal #1:

$ ./rebar3 shell --sname a --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V12.1.5  (abort with ^G)
(a@pc)1> nodes().
[]
(a@pc)2> net_adm:ping('b@pc').
pong
(a@pc)3> nodes().
[b@pc]

Terminal #2:

$ ./rebar3 shell --sname b --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V12.1.5  (abort with ^G)
(b@pc)1> nodes().
[a@pc]

Also, I suppose you can join to https://erlangforums.com/ - in the Erlang community forum you can find answers to any questions related to Erlang/OTP fast enough. P.S. The name and cookie you can set also by vm.args file.

Upvotes: 3

Related Questions