Node startup in elixir


If you want your beam apps to be able to talk to each other you will need to set a name and a cookie.

Names can be either short or long. Short named nodes must all be on the same machine. Long named nodes are written `name@machine` where `machine` is an ip address or dns name. Names can be set via the `--name` or `--sname` flag or by calling `Node.start/3`

Only nodes with identical cookies can communicate. Cookies are set with the `--cookie` flag or by calling `Node.set_cookie/1`.


For many of the applications I have written I decided to start the node programatically with the variables set in config files. The following pattern is repeated:

The `unless Node.alive()` bit is so I can override the node name using flags if I so choose. If I do not proved the `--name` flag on startup then the node name will be read from the config and the node started. If the flag is set then the node will already be in a distributed state ("alive").

The hex generation bit is so I can start a few instances of the same app on the same machine if I want. If this is not required I will skip that step.