问题
I'm trying to startup epmd separately from the erlang vm, in order to do monitoring on the connection handling.
This works fine, except for cases when the vm starts up before epmd.
Is there a way to make the erlang vm start without it starting the epmd on its own?
回答1:
Possible helpful questions/answers:
- Is there a way to stop Erlang servers from automatically starting epmd?
- Ensure epmd started
So inline with those questions/answers, I'd suggest to make the erlang vm service depend on epmd (which should be another service on its own). Also, if you run epmd as one of your very first services to run, it should be possible to make it start before erlang every time. But how to do this will actually depend on your operating system and deployment implementation details.
Also, a not-so-elegant solution, would be to change your init script, so it will wait for epmd to start, but manually. Your mileage may vary, and a very naive approach (but useful as an example) would be something like:
while [ true ]; do
pid=`pidof epmd`;
if [ "$pid" == "" ]; then
sleep 1; # Wait a bit more
else
break;
fi
done
# Continue initialization
Note that the code should contemplate a maximum number of attempts, also pidof only works on linux, etc. Not sure I like this solution, but can do the job.
And as less elegant solutions, you could replace the epmd that erlang will run with a binary of your own, that does whatever you need (like faking the epmd start or running your own, like in the code above).
Hope it helps!
回答2:
As of Erlang/OTP 19.0, there is a -start_epmd command line option which can be set to true
(the default) or false
.
If you pass -start_epmd false
on the command line and epmd is running, the Erlang node starts as usual. If epmd is not running, the Erlang node fails to start with this message:
$ erl -start_epmd false -sname foo
Protocol 'inet_tcp': register/listen error: econnrefused
If the Erlang node is not started as a distributed node (i.e., without passing -name
or -sname
), it neither starts nor attempts to connect to epmd, regardless of the -start_epmd
setting.
来源:https://stackoverflow.com/questions/21998439/starting-the-erlang-vm-without-epmd