[erlang-questions] Autogenerating node names

David Sveningsson ext@REDACTED
Fri Dec 12 10:31:42 CET 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Per Hedeland wrote:
> David Sveningsson <ext@REDACTED> wrote:
>> Thanks, but I was hoping to be able to skip the timer part. Does anyone
>> know when epmd forks? Before or after its initialization?
>>
>> Let me rephrase that, is epmd ready when "epmd -daemon" returns or must
>> one wait an unspecified time while it is starting?
> 
> I'd rephrase it as a suggestion, because it's a very nice way to
> start up a daemon, but epmd doesn't do that - it forks first
> (read the source:-). You can use erl_epmd:names/0 to check on
> its presence/readiness though, e.g. something like this:

You're right, I should have read the source. =)

> 
> start_epmd() ->
>     start_epmd(0, 10).
> 
> start_epmd(N, N) ->
>     {error, too_many_tries};
> start_epmd(M, N) ->
>     case erl_epmd:names() of
> 	{ok, _} ->
> 	    ok;
> 	_ when M == 0 ->
> 	    os:cmd("epmd -daemon"),
> 	    start_epmd(M+1, N);
> 	_ ->
> 	    timer:sleep(1),
> 	    start_epmd(M+1, N)
>     end.
> 
> Adjust "10" and "1" to taste, when I tried it I never managed to
> get to the sleep...
> 
> --Per Hedeland
> 
> 

Thanks, this works excellent!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.9 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAklCL34ACgkQ6pa1H/H5pqXDMwCg3HOQTvIeFngIoGjI6eotl1Xk
/AUAoNo4QMdn7haAVVjA5kUsrgPax2RL
=8U1V
-----END PGP SIGNATURE-----



More information about the erlang-questions mailing list