Ensure epmd started

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 05:49:01

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/18240319/ensure-epmd-started

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!