When running iex interactively, one can use
iex --cookie <cookie> --name <hostname>
How do I set the same values for cookie and name when running an executable created using mix escript.build?
I figured out that I need to create a vm.args file with the following contents
## Name of the node
-name name@host
## Cookie for distributed erlang
-setcookie cookie
So I created a vm.args file in the same directory as the executable file. But when I print Node.self(), I get :nonode@nohost.
So where do I store vm.args so that it is read by the executable?
As far as I know, vm.args is not read by escripts. You have (at least) 2 options:
Set these values in emu_args key passed to escript in project/0 in mix.exs:
def project do
[app: :m,
...,
escript: [main_module: M, emu_args: ["-name foo@bar -setcookie baz"]]]
end
Parse the CLI arguments and set the values in your main function:
defmodule M do
def main([name, cookie]) do
Node.start String.to_atom(name)
Node.set_cookie String.to_atom(cookie)
IO.inspect {Node.self, Node.get_cookie}
end
end
$ mix escript.build
$ ./m foo@bar baz
{:foo@bar, :baz}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With