I have a company Erlang application that is invoked by calling escript with a parameter -setcookie. Even though the cookie is specified on the command line the program still ends up creating $HOME/.erlang.cookie. This is creating a problem because sometimes the file gets the wrong permissions, which subsequently prevents the program from running.
I can't figure out why the permissions ever get changed, but if the program would stop creating it when I don't need it I wouldn't have a problem. Is there a way to make it so that the cookie file isn't created if a value is provided on the command line? Nothing seems to need this cookie file since the parameter is provided. (And if the file really needs to be created why is it created with a date but no time?
I have erts-10.3.1.
More info after @dolphin2017 answered. The script is actually provided by the distillery tools. We call nodetool which is coded with these bits of code.
main(Args) ->
ok = start_epmd(),
%% Extract the args
{RestArgs, TargetNode} = process_args(Args, [], undefined),
and process_args looks like the following:
process_args([], Acc, TargetNode) ->
{lists:reverse(Acc), TargetNode};
process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) ->
erlang:set_cookie(node(), list_to_atom(Cookie)),
process_args(Rest, Acc, TargetNode);
process_args(["-name", TargetName | Rest], Acc, _) ->
ThisNode = append_node_suffix(TargetName, "_maint_"),
{ok, _} = net_kernel:start([ThisNode, longnames]),
process_args(Rest, Acc, nodename(TargetName));
process_args(["-sname", TargetName | Rest], Acc, _) ->
ThisNode = append_node_suffix(TargetName, "_maint_"),
{ok, _} = net_kernel:start([ThisNode, shortnames]),
process_args(Rest, Acc, nodename(TargetName));
process_args([Arg | Rest], Acc, Opts) ->
process_args(Rest, [Arg | Acc], Opts).
It looks to me like this covers all the things that Dolphin2017 suggested, including the nodename, start and set_cookie so I'm not sure what else might be needed.
Having discovered now that this is from distillery I will also try taking this over to their various communication channels. But feel free to add more here.