From 6ce2beebd06d046e1d0e912017717753b62fb85a Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 21 Jan 2011 16:11:07 +0100 Subject: Synchronize nodetool escript with riak version --- priv/templates/simplenode.nodetool | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'priv/templates/simplenode.nodetool') 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. -- cgit v1.1 From ac5948d91029fc9875494be72dce022b2f937ff7 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 21 Jan 2011 16:12:09 +0100 Subject: Add file local variables to nodetool escript --- priv/templates/simplenode.nodetool | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'priv/templates/simplenode.nodetool') diff --git a/priv/templates/simplenode.nodetool b/priv/templates/simplenode.nodetool index f4bedff..cb524ce 100644 --- a/priv/templates/simplenode.nodetool +++ b/priv/templates/simplenode.nodetool @@ -1,4 +1,5 @@ -%% -*- erlang -*- +%% -*- mode:erlang;tab-width:4;erlang-indent-level:4;indent-tabs-mode:nil -*- +%% ex: ft=erlang ts=4 sw=4 et %% ------------------------------------------------------------------- %% %% nodetool: Helper Script for interacting with live nodes -- cgit v1.1 From b894682ba92baa0f258908cf5dacb5ec0cd14635 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 20 Jan 2011 18:56:42 +0100 Subject: Fix bug 294 --- priv/templates/simplenode.nodetool | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'priv/templates/simplenode.nodetool') diff --git a/priv/templates/simplenode.nodetool b/priv/templates/simplenode.nodetool index cb524ce..0318ca1 100644 --- a/priv/templates/simplenode.nodetool +++ b/priv/templates/simplenode.nodetool @@ -7,6 +7,7 @@ %% ------------------------------------------------------------------- main(Args) -> + ok = start_epmd(), %% Extract the args {RestArgs, TargetNode} = process_args(Args, [], undefined), @@ -73,6 +74,27 @@ process_args([Arg | Rest], Acc, Opts) -> process_args(Rest, [Arg | Acc], Opts). +start_epmd() -> + [] = os:cmd(epmd_path() ++ " -daemon"), + ok. + +epmd_path() -> + ErtsBinDir = filename:dirname(escript:script_name()), + Name = "epmd", + case os:find_executable(Name, ErtsBinDir) of + false -> + case os:find_executable(Name) of + false -> + io:format("Could not find epmd.~n"), + halt(1); + GlobalEpmd -> + GlobalEpmd + end; + Epmd -> + Epmd + end. + + nodename(Name) -> case string:tokens(Name, "@") of [_Node, _Host] -> -- cgit v1.1 From c466076ffb5a1ea4c00d49fefff0dcfbceb58236 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Mon, 31 Jan 2011 17:43:31 +0100 Subject: Clean up emacs file local variables --- priv/templates/simplenode.nodetool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'priv/templates/simplenode.nodetool') diff --git a/priv/templates/simplenode.nodetool b/priv/templates/simplenode.nodetool index 0318ca1..eb08fa4 100644 --- a/priv/templates/simplenode.nodetool +++ b/priv/templates/simplenode.nodetool @@ -1,4 +1,4 @@ -%% -*- mode:erlang;tab-width:4;erlang-indent-level:4;indent-tabs-mode:nil -*- +%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- %% ex: ft=erlang ts=4 sw=4 et %% ------------------------------------------------------------------- %% -- cgit v1.1