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, []}
]}.
1条答案
按热度按时间but5z9lq1#
我有3台计算机,我需要1台计算机的1个节点。如何为每台计算机编写一个脚本,使其自动完成?
我建议使用工具生成一个版本,例如rebar3,该版本包括一个 Boot 脚本,该脚本使用配置文件启动节点。
我还建议在您的情况下激活-heart flag,或者将该版本作为
systemd
服务安装。我可以在bash脚本中插入Erlang命令吗?最好的方法是什么?
您可以使用escript来处理这个问题,您可以检查这个问题以了解如何做到这一点(TL; DR:可以,但它会启动一个新节点)。
如何处理同步问题?可以将同步时间设置为无穷大吗?
从distributed applications,是的,您可以将同步时间设置为
infinity
。