summaryrefslogtreecommitdiff
path: root/priv/templates/simplenode.nodetool
diff options
context:
space:
mode:
authorTuncer Ayaz <tuncer.ayaz@gmail.com>2011-01-21 16:11:07 +0100
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-01-21 16:12:50 +0100
commit6ce2beebd06d046e1d0e912017717753b62fb85a (patch)
tree3db1e2bccab02945b6c622bad607beedf67ceb47 /priv/templates/simplenode.nodetool
parent0c191a5a604c1c3278715bd71856961230983638 (diff)
Synchronize nodetool escript with riak version
Diffstat (limited to 'priv/templates/simplenode.nodetool')
-rw-r--r--priv/templates/simplenode.nodetool37
1 files changed, 36 insertions, 1 deletions
diff --git a/priv/templates/simplenode.nodetool b/priv/templates/simplenode.nodetool
index 971f983..f4bedff 100644
--- a/priv/templates/simplenode.nodetool
+++ b/priv/templates/simplenode.nodetool
@@ -30,7 +30,8 @@ main(Args) ->
["reboot"] ->
io:format("~p\n", [rpc:call(TargetNode, init, reboot, [], 60000)]);
["rpc", Module, Function | RpcArgs] ->
- case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function), [RpcArgs], 60000) of
+ case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function),
+ [RpcArgs], 60000) of
ok ->
ok;
{badrpc, Reason} ->
@@ -39,6 +40,15 @@ main(Args) ->
_ ->
halt(1)
end;
+ ["rpcterms", Module, Function, ArgsAsString] ->
+ case rpc:call(TargetNode, list_to_atom(Module), list_to_atom(Function),
+ consult(ArgsAsString), 60000) of
+ {badrpc, Reason} ->
+ io:format("RPC to ~p failed: ~p\n", [TargetNode, Reason]),
+ halt(1);
+ Other ->
+ io:format("~p\n", [Other])
+ end;
Other ->
io:format("Other: ~p\n", [Other]),
io:format("Usage: nodetool {ping|stop|restart|reboot}\n")
@@ -78,3 +88,28 @@ append_node_suffix(Name, Suffix) ->
[Node] ->
list_to_atom(lists:concat([Node, Suffix, os:getpid()]))
end.
+
+
+%%
+%% Given a string or binary, parse it into a list of terms, ala file:consult/0
+%%
+consult(Str) when is_list(Str) ->
+ consult([], Str, []);
+consult(Bin) when is_binary(Bin)->
+ consult([], binary_to_list(Bin), []).
+
+consult(Cont, Str, Acc) ->
+ case erl_scan:tokens(Cont, Str, 0) of
+ {done, Result, Remaining} ->
+ case Result of
+ {ok, Tokens, _} ->
+ {ok, Term} = erl_parse:parse_term(Tokens),
+ consult([], Remaining, [Term | Acc]);
+ {eof, _Other} ->
+ lists:reverse(Acc);
+ {error, Info, _} ->
+ {error, Info}
+ end;
+ {more, Cont1} ->
+ consult(Cont1, eof, Acc)
+ end.