From 4825a495febf31f5be172d1a7e9b89a1514f1b5c Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 12 Apr 2019 14:32:04 -0600 Subject: include dist and epmd arguments from vm.args in remote shell and nodetool calls (#710) * remove unused VM_ARGS variable * include dist args in extended start scripts other calls --- priv/templates/extended_bin | 31 ++++++++++++++++++++++++++----- priv/templates/nodetool | 32 ++++++++++++++++++-------------- 2 files changed, 44 insertions(+), 19 deletions(-) (limited to 'priv') diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index e224c62..cfeb859 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -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 } @@ -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 @@ -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)" @@ -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 diff --git a/priv/templates/nodetool b/priv/templates/nodetool index 816be9c..62fa02e 100644 --- a/priv/templates/nodetool +++ b/priv/templates/nodetool @@ -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 @@ -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() -> -- cgit v1.2.3