In my efforts to get UPGRADE working (for a Phoenix application) for exrm releases on Microsoft Windows, I noticed that I could not ping the node, even though it was running. So I checked and it was using nonde@nohost.
To solve this, I called these functions from the main application module:
:net_kernel.start([name, :longnames])
:erlang.set_cookie(node(), cookie)
This works (at least it starts the node properly), but its not a proper solution.
erlsrv is being passed the node name by the application release bat file, but it seems that its not being set when the application is actually started.
I approached this initially thinking I needed to get this working quickly for operational purposes, but now want to do it properly by patching something in erlsrv.c or in the batch files.
For your information, the following code is how I got my application working:
use Application
@version Mix.Project.config[:version]
def version(), do: @version
@env Mix.env
def env(), do: @env
defp start_network(name, cookie) when is_atom(name) do
case :net_kernel.start([name, :longnames]) do
{:ok, pid} -> :erlang.set_cookie(node(), cookie)
{:error, {{:already_started, pid}, _}} -> :already_started
end
end
defp get_vm_args() do
{:ok, data} = File.read(Path.expand("../../releases/#{version()}/vm.args", System.cwd!()))
end
defp get_node_name(data) do
case Regex.run(~r/-name ([^\n]+)/, data) do
nil -> nil
[_, name] -> String.to_atom(name)
end
end
defp get_cookie(data) do
case Regex.run(~r/-setcookie ([^\n]+)/, data) do
nil -> nil
[_, cookie] -> String.to_atom(cookie)
end
end
def start(_type, _args) do
import Supervisor.Spec
if node() == :nonode@nohost and env() == :prod do
data = get_vm_args()
node_name = get_node_name(data)
cookie = get_cookie(data)
start_network(node_name, cookie)
end
… followed by the normal supervision startup stuff.
I will be deleting this code once I get erlsrv.c patched, so I’m not really posting this asking for advice about how to do it in Elixir, this is to illustrate what I needed to do, i.e. what erlsvr.c is not doing now. I’m posting here, hoping for help regarding erlsvr.c and the batch files
Thanks