[ejabberd] How to add new commands to ejabberdctl?

Horacio Sanson hsanson at gmail.com
Fri Feb 21 14:27:24 MSK 2014


I am trying to add a new command to ejabberdctl to facilitate the
configuration of clusters but I am having some problems. Below is my code:


#############################################
-module(mod_cluster).

-behavior(gen_mod).

-export([start/2,stop/1,cluster_test/1]).

-include("ejabberd.hrl").
-include("ejabberd_commands.hrl").
-include("mod_roster.hrl").
-include("jlib.hrl").

start(_Host, _Opts) ->
  ejabberd_commands:register_commands(commands()).

stop(_Host) ->
  ejabberd_commands:unregister_commands(commands()).

commands() ->
  [
    #ejabberd_commands{name = cluster_test, tags = [server],
                       desc = "Test connectivity with remote node",
                       module = ?MODULE, function = cluster_test,
                       args = [{node, string}],
                       result = {res, rescode}}
  ].


cluster_test(NodeName) ->
        case net_adm:ping(NodeName) of 'pong' ->
                io:format("server is reachable.~n"),
                ok;
        _ ->
                io:format("server could NOT be reached.~n"),
                error
        end.

##############################################

This code adds a cluster_test() function that checks connectivity with
remote ejabberd nodes. I took this code from [1].

Then registers this function as a command to ejabberctl. The idea is to be
able to run the function from a terminal like:

  > sudo ejabberdctl cluster_test  ejabberd at domain.local

If I use the debug console and call the function directly it works as
expected but invoking it from the terminal gives this error:

###################################################
Problem 'error function_clause' occurred executing the command.
Stacktrace: [{net_adm,ping,["jabber01"]},
             {mod_cluster,cluster_test,1},
             {ejabberd_ctl,call_command,3},
             {ejabberd_ctl,try_call_command,3},
             {ejabberd_ctl,process2,3},
             {ejabberd_ctl,process,1},
             {rpc,'-handle_call_call/6-fun-0-',5}]
####################################################

I used the code from mod_admin_extra [2] as base to implement this but I am
totally lost about Erlang.

Any tips on what I may be doing wrong are greatly appreciated.

[1] -
http://chad.ill.ac/post/35967173942/easy-ejabberd-clustering-guide-mnesia-mysql

[2] -
https://github.com/processone/ejabberd-contrib/blob/master/mod_admin_extra/src/mod_admin_extra.erl

regards,
Horacio
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.jabber.ru/pipermail/ejabberd/attachments/20140221/336defd8/attachment.html>


More information about the ejabberd mailing list