I have two Erlang applications, for example, app1
and app2
. I want to run them on three nodes when each node has its own config file.
Also, I need to run app1
before app2
.
app1
must be running on every node. app2
is the same program for all nodes, but only one node runs it at the same time; the other nodes waits for the case of the current node will fail.
Example of running:
node 1:
erl -sname cp1 config cp1
application:start(app1).
application:start(app2).
node 2:
erl -sname cp2 config cp2
application:start(app1).
application:start(app2).
node 3:
erl -sname cp3 config cp3
application:start(app1).
application:start(app2).
All nodes need to start together because of the sync time (I set this parameter to 10000) in the config file and the same for app2
.
To check that my program works as I want, I do this by myself, that's easy: I have control on the timing, I open a terminator with 3 terminals, do a copy-paste to commands and everything is ok.
My questions are:
I have 3 computers. I need one node for one computer. How to write a script for each computer that does it automatically?
Can I insert Erlang commands to bash script? What the best way to do this?
How can I deal with the problem of sync? Can I set sync time to infinity?
cp1 code: (same for the others, just with changes in sync mandatory)
[{kernel,
[{distributed, [{app2, 2000, [{cp1@dev1, cp2@dev1, cp3@dev1}]}
]},
{sync_nodes_mandatory, [cp2@dev1, cp3@dev1]},
{sync_nodes_timeout, 10000}
]
}
].
app2.app code:
{application, app2,
[{description, "An OTP application"},
{vsn, "0.1.0"},
{registered, []},
{mod, {app2_app, []}},
{applications,
[kernel,
stdlib,
app1
]},
{env,[]},
{modules, []},
{licenses, ["Apache 2.0"]},
{links, []}
]}.