summaryrefslogtreecommitdiff
path: root/priv/templates/simplenode.nodetool
diff options
context:
space:
mode:
authorAlexey Romanov <alexey.v.romanov@gmail.com>2011-02-21 12:41:20 +0300
committerAlexey Romanov <alexey.v.romanov@gmail.com>2011-02-21 12:41:20 +0300
commit7dc371d8a3b9a6e2ab9f814c0d2536cf638ceb99 (patch)
tree174193ae08d2824164ba99e63f696a6593ee63c6 /priv/templates/simplenode.nodetool
parent2ceeb3272139b7569c8dabc215ca1e7063b0d385 (diff)
parent6056c63eed288736c912c82d6f36aa7dd055f9ca (diff)
Merge branch 'master' of https://github.com/basho/rebar
Diffstat (limited to 'priv/templates/simplenode.nodetool')
-rw-r--r--priv/templates/simplenode.nodetool62
1 files changed, 60 insertions, 2 deletions
diff --git a/priv/templates/simplenode.nodetool b/priv/templates/simplenode.nodetool
index 971f983..eb08fa4 100644
--- a/priv/templates/simplenode.nodetool
+++ b/priv/templates/simplenode.nodetool
@@ -1,4 +1,5 @@
-%% -*- erlang -*-
+%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ft=erlang ts=4 sw=4 et
%% -------------------------------------------------------------------
%%
%% nodetool: Helper Script for interacting with live nodes
@@ -6,6 +7,7 @@
%% -------------------------------------------------------------------
main(Args) ->
+ ok = start_epmd(),
%% Extract the args
{RestArgs, TargetNode} = process_args(Args, [], undefined),
@@ -30,7 +32,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 +42,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")
@@ -62,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] ->
@@ -78,3 +111,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.