Add ability to disable timeout for ejabberdctl command
authorPaweł Chmielowski <pchmielowski@process-one.net>
Tue, 8 Dec 2015 10:25:26 +0000 (11:25 +0100)
committerPaweł Chmielowski <pchmielowski@process-one.net>
Tue, 8 Dec 2015 10:25:26 +0000 (11:25 +0100)
ejabberdctl.template
src/ejabberd_ctl.erl

index bd791cedab12ee9195ae93cfd9febc3046e218c4..5fbcf94ee17d9faf24da1bec7c39ea7a2da3bde0 100755 (executable)
@@ -48,6 +48,7 @@ while [ $# -ne 0 ] ; do
     shift
     case $PARAM in
         --) break ;;
+        --no-timeout) EJABBERD_NO_TIMEOUT="--no-timeout" ;;
         --node) ERLANG_NODE_ARG=$1 ; shift ;;
         --config-dir) ETC_DIR="$1" ; shift ;;
         --config) EJABBERD_CONFIG_PATH="$1" ; shift ;;
@@ -418,7 +419,7 @@ ctlexec()
       -hidden \
       -pa $EJABBERD_EBIN_PATH \
       $KERNEL_OPTS \
-      -s ejabberd_ctl -extra $ERLANG_NODE $COMMAND"
+      -s ejabberd_ctl -extra $ERLANG_NODE $EJABBERD_NO_TIMEOUT $COMMAND"
 }
 
 # stop epmd if there is no other running node
index ec916b32b54e94a51be8cbd99732295be6dfa9aa..b0a1069d972df95a1f19c859c4cb1b13b6b839a1 100644 (file)
 %%-----------------------------
 
 start() ->
-    case init:get_plain_arguments() of
-       [SNode | Args] ->
-           SNode1 = case string:tokens(SNode, "@") of
-                        [_Node, _Server] ->
-                            SNode;
-                        _ ->
-                            case net_kernel:longnames() of
-                                true ->
-                                    lists:flatten([SNode, "@", inet_db:gethostname(),
-                                                    ".", inet_db:res_option(domain)]);
-                                false ->
-                                     lists:flatten([SNode, "@", inet_db:gethostname()]);
-                                _ ->
-                                    SNode
-                            end
-                    end,
-           Node = list_to_atom(SNode1),
-           Status = case rpc:call(Node, ?MODULE, process, [Args], 60000) of
-                        {badrpc, Reason} ->
-                            print("Failed RPC connection to the node ~p: ~p~n",
-                                   [Node, Reason]),
-                            %% TODO: show minimal start help
-                            ?STATUS_BADRPC;
-                        S ->
-                            S
-                    end,
-           halt(Status);
-       _ ->
-           print_usage(),
-           halt(?STATUS_USAGE)
-    end.
+    [SNode, Timeout, Args] = case init:get_plain_arguments() of
+                                 [SNode2, "--no-timeout" | Args2] ->
+                                     [SNode2, infinity, Args2];
+                                 [SNode3 | Args3] ->
+                                     [SNode3, 10000, Args3];
+                                 _ ->
+                                     print_usage(),
+                                     halt(?STATUS_USAGE)
+                             end,
+    SNode1 = case string:tokens(SNode, "@") of
+                 [_Node, _Server] ->
+                     SNode;
+                 _ ->
+                     case net_kernel:longnames() of
+                         true ->
+                             lists:flatten([SNode, "@", inet_db:gethostname(),
+                                            ".", inet_db:res_option(domain)]);
+                         false ->
+                             lists:flatten([SNode, "@", inet_db:gethostname()]);
+                         _ ->
+                             SNode
+                     end
+             end,
+    Node = list_to_atom(SNode1),
+    Status = case rpc:call(Node, ?MODULE, process, [Args], Timeout) of
+                 {badrpc, Reason} ->
+                     print("Failed RPC connection to the node ~p: ~p~n",
+                           [Node, Reason]),
+                     %% TODO: show minimal start help
+                     ?STATUS_BADRPC;
+                 S ->
+                     S
+             end,
+    halt(Status).
 
 init() ->
     ets:new(ejabberd_ctl_cmds, [named_table, set, public]),
@@ -470,7 +473,7 @@ print_usage(HelpMode, MaxC, ShCode) ->
        get_list_ctls(),
 
     print(
-       ["Usage: ", ?B("ejabberdctl"), " [--node ", ?U("nodename"), "] [--auth ",
+       ["Usage: ", ?B("ejabberdctl"), " [--no-timeout] [--node ", ?U("nodename"), "] [--auth ",
        ?U("user"), " ", ?U("host"), " ", ?U("password"), "] ",
        ?U("command"), " [", ?U("options"), "]\n"
        "\n"