本文介绍了确保epmd开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  {A,B,C} =现在(),
Nodename = list_to_atom(列表:flatten(io_lib:format(
test-〜b-〜b-〜b @ localhost,[A,B,C]))
{ok,_} = net_kernel:start([Nodename,shortnames]),

只要一个分布式的Erlang节点在上一次在机器上运行,这样epmd仍然在运行,但是在构建服务器上,我不能假设是这样的。



我通过将此添加到我的测试中解决了问题:

  _ = os:cmd(epmd -daemon),

但感觉就像一个黑客。在运行 net_kernel:start 之前是否有更好/更好的方式来确保epmd已经启动?

解决方案

不,您不能确保EPMD以更干净的方式开始。



TL; DR



EPMD是一个外部程序,中实现。虽然 net_kernel:start / 1 负责,它实际上并不触发必须明确启动的EPMD守护程序。在 erl 命令中指定 -sname 选项时,我看了一下EPMD的启动方式,惊喜 - 我发现开始的。


I have an eunit test that generates a unique node name and starts distribution:

{A,B,C} = now(),
Nodename = list_to_atom(lists:flatten(io_lib:format(
    "test-~b-~b-~b@localhost", [A, B, C]))),
{ok, _} = net_kernel:start([Nodename, shortnames]),

This works fine as long as a distributed Erlang node has been running on the machine at some previous time, and thus epmd is still running, but on the build server I can't assume that's the case.

I solved the problem by adding this to my test:

_ = os:cmd("epmd -daemon"),

but it feels like a hack. Is there a better/nicer way to ensure that epmd is started before running net_kernel:start?

解决方案

No, you cannot ensure EPMD is started in a cleaner way.

TL;DR

EPMD is an external program, implemented in C. Whilst net_kernel:start/1 takes care of creating the net_sup supervisor, it does not actually trigger the EPMD daemon, which has to be started explicitely. I had a look at how EPMD is started when the -sname option is specified in the erl command and - surprise, surprise - I discovered that the epmd program is started via a system() C call.

这篇关于确保epmd开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:15