如何使用单独的脚本连接到 ejabberd 的 Mnesia 数据库?

发布于 2025-01-04 15:10:25 字数 148 浏览 4 评论 0原文

我正在尝试从单独的脚本将隶属关系数据插入 ejabberd 的 Mnesia 数据库中。我是一名 Erlang 初学者,虽然我可以弄清楚如何创建和使用单独的 Mnesia 数据库,但我无法弄清楚如何连接到 ejabberd 的数据库。使用相同的“-mnesia dir”似乎还不够。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扮仙女 2025-01-11 15:10:25

这个问题归结为如何在 Erlang 中进行 rpc 调用的问题。

  1. 确保 ejabberd 使用节点主机部分的完全限定主机名或 IP 地址运行。这在我的安装中在 /etc/ejabberd/ejabberdctl.cfg 中指定为 EJABBERD_NODE。如果您确实必须在此步骤中更改主机名,请参阅 https://git.process-one.net/ejabberd/mainline/blobs/raw/v2.1.10/doc/guide.html#htoc79 (“更改计算机主机名”)。

  2. 使用 -name 或 -sname 启动 shell 或脚本,并使用具有与上述相同限制的主机。

  3. 您已准备好使用 Erlang 的内置 RPC。例如:

来自您的 shell 或脚本)

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]).

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]).
神回复 2025-01-11 15:10:25

只需使用命令ejabberdctl debug

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

just use command ejabberdctl debug

mnesia:info(). %to overview mnesia 
mnesia:schema(schema). %see table named schema`s detail
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文