]> granicus.if.org Git - ejabberd/commitdiff
Make some standard admin command to get Mnesia info
authorMickael Remond <mremond@process-one.net>
Fri, 3 May 2019 12:59:24 +0000 (14:59 +0200)
committerMickael Remond <mremond@process-one.net>
Fri, 3 May 2019 12:59:24 +0000 (14:59 +0200)
src/ejabberd_admin.erl
src/ejabberd_ctl.erl

index 82c35e40e3b1401dddcca1968a5184a96ed4dbd6..d044f12706092c980fbdc4199e9bfadc9d47c075 100644 (file)
@@ -50,6 +50,7 @@
         set_master/1,
         backup_mnesia/1, restore_mnesia/1,
         dump_mnesia/1, dump_table/2, load_mnesia/1,
+        mnesia_info/0, mnesia_table_info/1,
         install_fallback_mnesia/1,
         dump_to_textfile/1, dump_to_textfile/2,
         mnesia_change_nodename/4,
@@ -357,6 +358,16 @@ get_commands_spec() ->
                        args_desc = ["Full path to the text file"],
                        args_example = ["/var/lib/ejabberd/database.txt"],
                        args = [{file, string}], result = {res, restuple}},
+     #ejabberd_commands{name = mnesia_info, tags = [mnesia],
+                       desc = "Dump info on global Mnesia state",
+                       module = ?MODULE, function = mnesia_info,
+                       args = [], result = {res, string}},
+     #ejabberd_commands{name = mnesia_table_info, tags = [mnesia],
+                       desc = "Dump info on Mnesia table state",
+                       module = ?MODULE, function = mnesia_table_info,
+                       args_desc = ["Mnesia table name"],
+                       args_example = ["roster"],
+                       args = [{table, string}], result = {res, string}},
      #ejabberd_commands{name = install_fallback, tags = [mnesia],
                        desc = "Install the database from a fallback file",
                        module = ?MODULE, function = install_fallback_mnesia,
@@ -716,6 +727,13 @@ load_mnesia(Path) ->
            {cannot_load, String}
     end.
 
+mnesia_info() ->
+    lists:flatten(io_lib:format("~p", [mnesia:system_info(all)])).
+
+mnesia_table_info(Table) ->
+    ATable = list_to_atom(Table),
+    lists:flatten(io_lib:format("~p", [mnesia:table_info(ATable, all)])).
+
 install_fallback_mnesia(Path) ->
     case mnesia:install_fallback(Path) of
        ok ->
index 9cc4f83c01fdaacc3eb38382f86fcb03b9903780..f4a898c157b69b79ad0c5455b7acbd06906cda3f 100644 (file)
@@ -190,6 +190,9 @@ process(["restart"], _Version) ->
     init:restart(),
     ?STATUS_SUCCESS;
 
+%% TODO: Mnesia operations should not be hardcoded in ejabberd_ctl module.
+%% For now, I leave them there to avoid breaking those commands for people that
+%% may be using it (as format of response is going to change).
 process(["mnesia"], _Version) ->
     print("~p~n", [mnesia:system_info(all)]),
     ?STATUS_SUCCESS;