4

I want to change the node name of a beam instance dynamically.

The usecase is in a cluster of VM's I would like the startup process to lookup the ip information and then pick a name from that.

node()
# => :nonode@nohost

# Lookup ip and change name

node()
# => :myapp@x.x.x.x
Peter Saxton
  • 4,466
  • 5
  • 33
  • 51

1 Answers1

5

Yes, you can use net_kernel:start/1 in Erlang or Node.start/{1,2,3} in Elixir:

1> node().
nonode@nohost
2> net_kernel:start(['myapp@1.2.3.4']).
{ok,<0.60.0>}
(myapp@1.2.3.4)3> node().
'myapp@1.2.3.4'
iex(1)> Node.self
:nonode@nohost
iex(2)> Node.start :"myapp@1.2.3.4"
{:ok, #PID<0.83.0>}
iex(myapp@1.2.3.4)3> Node.self
:"myapp@1.2.3.4"
Ian Hunter
  • 9,466
  • 12
  • 61
  • 77
Dogbert
  • 212,659
  • 41
  • 396
  • 397
  • starting from a new iex shell I get an error when i try this. {:error, {{:shutdown, {:failed_to_start_child, :net_kernel, {:EXIT, {:function_clause, [{:net_kernel, :start_link, [:"dev@172.28.128.7", false], [file: 'net_kernel.erl', line: 357]}, – Peter Saxton Oct 21 '16 at 11:20
  • 1
    Looks like `epmd` is not running on the system. Check out this question and the answer: http://stackoverflow.com/questions/18240319/ensure-epmd-started – Dogbert Oct 21 '16 at 11:58