Skip to content

Commit

Permalink
include dist and epmd arguments from vm.args in remote shell and node…
Browse files Browse the repository at this point in the history
…tool calls (#710)

* remove unused VM_ARGS variable

* include dist args in extended start scripts other calls
  • Loading branch information
tsloughter authored Apr 12, 2019
1 parent a6107ec commit 4825a49
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 19 deletions.
31 changes: 26 additions & 5 deletions priv/templates/extended_bin
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ relx_rem_sh() {

# Setup remote shell command to control node
exec "$BINDIR/erl" "$NAME_TYPE" "$id" -remsh "$NAME" -boot start_clean \
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" \
-boot_var ERTS_LIB_DIR "$ERTS_LIB_DIR" $MAYBE_DIST_ARGS \
-setcookie "$COOKIE" -hidden -kernel net_ticktime $TICKTIME
}

Expand All @@ -189,8 +189,16 @@ relx_gen_id() {
relx_nodetool() {
command="$1"; shift

"$ERTS_DIR/bin/escript" "$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
-setcookie "$COOKIE" "$command" $@
if [ -z "${START_EPMD}" ]; then
ERL_FLAGS="${ERL_FLAGS} ${MAYBE_DIST_ARGS}" "$ERTS_DIR/bin/escript" \
"$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
-setcookie "$COOKIE" "$command" $@
else
ERL_FLAGS="${ERL_FLAGS} ${MAYBE_DIST_ARGS}" "$ERTS_DIR/bin/escript" \
"$ROOTDIR/bin/nodetool" "$NAME_TYPE" "$NAME" \
$START_EPMD -setcookie "$COOKIE" "$command" $@
fi

}

# Run an escript in the node's environment
Expand Down Expand Up @@ -454,6 +462,21 @@ NAME_ARG=$(eval echo "${NAME_ARG}")
NAME_TYPE="$(echo "$NAME_ARG" | awk '{print $1}')"
NAME="$(echo "$NAME_ARG" | awk '{print $2}')"

# Extract dist arguments
MAYBE_DIST_ARGS=""
PROTO_DIST="$(grep '^-proto_dist' "$VMARGS_PATH" || true)"
if [ "$PROTO_DIST" ]; then
MAYBE_DIST_ARGS="${PROTO_DIST}"
fi
START_EPMD="$(grep '^-start_epmd' "$VMARGS_PATH" || true)"
if [ "$START_EPMD" ]; then
MAYBE_DIST_ARGS="${MAYBE_DIST_ARGS} ${START_EPMD}"
fi
EPMD_MODULE="$(grep '^-epmd_module' "$VMARGS_PATH" || true)"
if [ "$EPMD_MODULE" ]; then
MAYBE_DIST_ARGS="${MAYBE_DIST_ARGS} ${EPMD_MODULE}"
fi

# Extract the target cookie
# Do this before relx_get_nodename so we can use it and not create a ~/.erlang.cookie
COOKIE_ARG="$(grep '^-setcookie' "$VMARGS_PATH" || true)"
Expand Down Expand Up @@ -483,8 +506,6 @@ export NAME
test -z "$PIPE_DIR" && PIPE_BASE_DIR='/tmp/erl_pipes/'
PIPE_DIR="${PIPE_DIR:-/tmp/erl_pipes/$NAME/}"

VM_ARGS="$(grep -v -E '^#|^-name|^-sname|^-setcookie|^-heart|^-args_file' "$VMARGS_PATH" | xargs | sed -e 's/ / /g')"

cd "$ROOTDIR"

# Check the first argument for instructions
Expand Down
32 changes: 18 additions & 14 deletions priv/templates/nodetool
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
%% -------------------------------------------------------------------

main(Args) ->
ok = start_epmd(),
%% Extract the args
{RestArgs, TargetNode} = process_args(Args, [], undefined),
{RestArgs, TargetNode, StartEpmd} = process_args(Args, [], undefined, true),

ok = start_epmd(StartEpmd),

%% See if the node is currently running -- if it's not, we'll bail
case {net_kernel:hidden_connect_node(TargetNode), net_adm:ping(TargetNode)} of
Expand Down Expand Up @@ -87,25 +88,28 @@ main(Args) ->
end,
net_kernel:stop().

process_args([], Acc, TargetNode) ->
{lists:reverse(Acc), TargetNode};
process_args(["-setcookie", Cookie | Rest], Acc, TargetNode) ->
process_args([], Acc, TargetNode, StartEpmd) ->
{lists:reverse(Acc), TargetNode, StartEpmd};
process_args(["-setcookie", Cookie | Rest], Acc, TargetNode, StartEpmd) ->
erlang:set_cookie(node(), list_to_atom(Cookie)),
process_args(Rest, Acc, TargetNode);
process_args(["-name", TargetName | Rest], Acc, _) ->
process_args(Rest, Acc, TargetNode, StartEpmd);
process_args(["-start_epmd", StartEpmd | Rest], Acc, TargetNode, _StartEpmd) ->
process_args(Rest, Acc, TargetNode, list_to_atom(StartEpmd));
process_args(["-name", TargetName | Rest], Acc, _, StartEpmd) ->
ThisNode = append_node_suffix(TargetName, "_maint_"),
{ok, _} = net_kernel:start([ThisNode, longnames]),
process_args(Rest, Acc, nodename(TargetName));
process_args(["-sname", TargetName | Rest], Acc, _) ->
process_args(Rest, Acc, nodename(TargetName), StartEpmd);
process_args(["-sname", TargetName | Rest], Acc, _, StartEpmd) ->
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).

process_args(Rest, Acc, nodename(TargetName), StartEpmd);
process_args([Arg | Rest], Acc, Opts, StartEpmd) ->
process_args(Rest, [Arg | Acc], Opts, StartEpmd).

start_epmd() ->
start_epmd(true) ->
[] = os:cmd("\"" ++ epmd_path() ++ "\" -daemon"),
ok;
start_epmd(_) ->
ok.

epmd_path() ->
Expand Down

0 comments on commit 4825a49

Please sign in to comment.