Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you assign a default name to a node in Elixir?

Tags:

elixir

I'm working on some distributed code in Elixir, however, I have to keep passing --name to assign a name to my node. Is there anyway to do this by default? I'd like to set something in my .elixirrc file so that each server always has the same node name.

like image 843
mjs2600 Avatar asked Jan 12 '23 21:01

mjs2600


2 Answers

Short answer: no.

Long answer: you can given a name for a node dynamically, so if you find yourself doing many setup tasks (setting cookies, naming nodes, etc), you can have a script that helps you get it started. You will need Elixir v0.10.1 (currently master) for this:

# boot.exs
:net_kernel.start([:foobar, :shortnames])

And then start it:

$ mix run boot.exs

Docs for net_kernel can be found here.

like image 128
José Valim Avatar answered Mar 29 '23 16:03

José Valim


Node.start(:"foobar", :shortnames)

or if you want to use longname

Node.start(:"[email protected]")

Assuming IP address 172.17.0.1. This has to be IP address of machine on which you want to create your node.

You can access this node by simply runningNode.self

like image 20
Sanket Achari Avatar answered Mar 29 '23 17:03

Sanket Achari