From 6e419a99f6b58817a8d39901a053ee752596cff8 Mon Sep 17 00:00:00 2001 From: Anthony Molinaro Date: Mon, 28 Mar 2016 10:55:45 -0700 Subject: provide eval command for nodetool and start script --- priv/templates/extended_bin | 11 ++++++++++- priv/templates/nodetool | 31 ++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/priv/templates/extended_bin b/priv/templates/extended_bin index 3c71c84..d7a9a0b 100755 --- a/priv/templates/extended_bin +++ b/priv/templates/extended_bin @@ -449,9 +449,18 @@ case "$1" in relx_nodetool rpcterms $@ ;; + eval) + # Make sure a node IS running + if ! relx_nodetool "ping" > /dev/null; then + echo "Node is not running!" + exit 1 + fi + shift + relx_nodetool "eval" $@ + ;; *) - echo "Usage: $REL_NAME {start|start_boot |foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot |attach|remote_console|upgrade|escript|rpc|rpcterms}" + echo "Usage: $REL_NAME {start|start_boot |foreground|stop|restart|reboot|pid|ping|console|console_clean|console_boot |attach|remote_console|upgrade|escript|rpc|rpcterms|eval}" exit 1 ;; esac diff --git a/priv/templates/nodetool b/priv/templates/nodetool index b3cd247..1f409f5 100644 --- a/priv/templates/nodetool +++ b/priv/templates/nodetool @@ -52,9 +52,38 @@ main(Args) -> Other -> io:format("~p\n", [Other]) end; + ["eval" | ListOfArgs] -> + % shells may process args into more than one, and end up stripping + % spaces, so this converts all of that to a single string to parse + String = binary_to_list( + list_to_binary( + string:join(ListOfArgs," ") + ) + ), + + % then just as a convenience to users, if they forgot a trailing + % '.' add it for them. + Normalized = + case lists:reverse(String) of + [$. | _] -> String; + R -> lists:reverse([$. | R]) + end, + + % then scan and parse the string + {ok, Scanned, _} = erl_scan:string(Normalized), + {ok, Parsed } = erl_parse:parse_exprs(Scanned), + + % and evaluate it on the remote node + case rpc:call(TargetNode, erl_eval, exprs, [Parsed, [] ]) of + {value, Value, _} -> + io:format ("~p\n",[Value]); + {badrpc, Reason} -> + io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]), + halt(1) + end; Other -> io:format("Other: ~p\n", [Other]), - io:format("Usage: nodetool {ping|stop|restart|reboot|rpc|rpcterms} [RPC]\n") + io:format("Usage: nodetool {ping|stop|restart|reboot|rpc|rpcterms|eval [Terms]} [RPC]\n") end, net_kernel:stop(). -- cgit v1.2.3