Commits

dizzyd committed 674904b

Adding wait-for-service command to facilitate waiting for full KV system to come up; adding rpcterms command to nodetool for easier shell scripting

Comments (0)

Files changed (2)

rel/files/nodetool

         ["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} ->
                 _ ->
                     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")
         [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.

rel/files/riak-admin

         $NODETOOL rpc riak_kv_console transfers $@
         ;;
 
+    services)
+        $NODETOOL rpcterms riak_core_node_watcher services ''
+        ;;
+
+    wait-for-service)
+        SVC=$2
+        if [ $# -lt 2 ]; then
+            echo "Usage: $SCRIPT wait-for-service <service_name>"
+            exit 1
+        fi
+
+        while (true); do
+            RES=`$NODETOOL rpcterms riak_core_node_watcher services ''| grep $SVC`
+            if [ ! -z "$RES" ]; then
+                echo "$SVC is up"
+                exit 0
+            else
+                echo "$SVC is not up"
+            fi
+            sleep 3
+        done
+        ;;
+
     js_reload)
         # Reload all Javascript VMs
         RES=`$NODETOOL ping`
         ;;
     *)
         echo "Usage: $SCRIPT { join | leave | backup | restore | test | status | "
-        echo "                    reip | js_reload | ringready | transfers }"
+        echo "                    reip | js_reload | wait-for-service | ringready | "
+        echo "                    transfers }"
         exit 1
         ;;
 esac