Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set Erlang node name, when run an Erlang application by basho rebar from command line

Tags:

erlang

rebar

I have compiled my Erlang application by using basho rebar which makes an stand-alone escript executable file. I run it from command line like: ./myapp myconfig.config

My questio is that how can I determine the Erlang node name that run my application. When in my application I run 'node()' command, it returns by default "nonode@nohost" but I want to give my name to that node (e.g. [email protected]), so when I run 'node()' in my application, I like to see '[email protected]' instead of 'nonode@nohost'

I know about "erlang -name '[email protected]'" but please consider I run the application from command line. I think an Erlang VM is run and terminate during the application life-time automatically.

like image 626
Sepehr Samini Avatar asked Dec 29 '12 02:12

Sepehr Samini


1 Answers

The best way is of course to set nodename in command line through "-sname node" or "-name node@host". But it is possible to use `net_kernel' module instead. It is described at http://www.erlang.org/doc/man/net_kernel.html

$ erl
Erlang R15B01 (erts-5.9.1) [source] [64-bit] [smp:2:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.9.1  (abort with ^G)
1> node().
nonode@nohost
2> net_kernel:start([rumata, shortnames]).
{ok,<0.34.0>}
(rumata@rumata-osx)3> node().
'rumata@rumata-osx'
(rumata@rumata-osx)4> net_kernel:stop().
ok
5> node().
nonode@nohost
6> net_kernel:start(['rumata@myhost', longnames]). 
{ok,<0.44.0>}
(rumata@myhost)7> node().
rumata@myhost
like image 199
Dmitry Belyaev Avatar answered Oct 19 '22 20:10

Dmitry Belyaev