Andrew B.
Andrew B.

Reputation: 1227

How can I connect to ejabberd's Mnesia database with a separate script?

I'm trying to insert affiliation data into ejabberd's Mnesia databse from a separate script. I'm an Erlang beginner, and while I can figure out how to create and use a separate Mnesia database, I can't figure out how to connect to ejabberd's. Using the same "-mnesia dir" does not seem to suffice.

Upvotes: 2

Views: 5593

Answers (2)

mahengyang
mahengyang

Reputation: 289

just use command ejabberdctl debug

mnesia:info(). %to overview mnesia 
mnesia:schema(schema). %see table named schema`s detail

Upvotes: 2

Andrew B.
Andrew B.

Reputation: 1227

The question reduces to the question of how to make rpc calls in Erlang.

  1. Ensure that ejabberd is running with either a fully-qualified hostname or IP address for host part of the node. This is specified in my installation as EJABBERD_NODE in /etc/ejabberd/ejabberdctl.cfg. If you do have to change the hostname in this step, consult https://git.process-one.net/ejabberd/mainline/blobs/raw/v2.1.10/doc/guide.html#htoc79 ("Change Computer Hostname").

  2. Start your shell or script with -name or -sname and use a host with the same restriction as above.

  3. You're ready to use Erlang's built-in RPC. For example:

(from your shell or script)

Cookie = 'YOUR_EJABBERD_COOKIE'. % mine was found in /var/lib/ejabberd/.erlang.cookie
EjabberdNode = '[email protected]'. % or whatever you set as EJABBERD_NODE
erlang:set_cookie(EjabberdNode, Cookie).
net_adm:ping(EjabberdNode).
rpc:call(EjabberdNode, mnesia, system_info, [tables]).

Upvotes: 5

Related Questions