Erlang 在生产中启动应用程序

发布于 2024-11-29 07:23:36 字数 619 浏览 0 评论 0原文

当我在本地主机上测试我的 erlang 应用程序时,我有一个启动服务器的脚本,如下所示:

#!/bin/sh
PWD="$(pwd)"
NAME="$(basename $PWD)"
erl -pa "$PWD/ebin" deps/*/ebin -boot start_sasl \
    -name [email protected] \
    -s reloader \
    -s $NAME \
    -setcookie some_random_cookie \
    +K true \
    +P 65536 

这会提示打开 Erlang shell,然后从那里输入类似以下内容的内容:

application:start(myapp)< /code>

这对于开发目的来说很好,但是如何在生产中部署它?截至目前,我能想到的唯一方法是启动一个屏幕进程并从中分离。我认为情况不应该如此。我正在使用钢筋,如果这有帮助的话。

When I'm testing my erlang application on localhost, I have a script that starts the server that looks like the following:

#!/bin/sh
PWD="$(pwd)"
NAME="$(basename $PWD)"
erl -pa "$PWD/ebin" deps/*/ebin -boot start_sasl \
    -name [email protected] \
    -s reloader \
    -s $NAME \
    -setcookie some_random_cookie \
    +K true \
    +P 65536 

This prompts open the Erlang shell and from there I would type something like:

application:start(myapp)

This is fine for development purposes, but how do I deploy this in production? As of right now, the only way I can think of doing this is by starting a screen process and detaching from it. I don't think that should be the case. I am using rebar, if that helps at all.

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

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

发布评论

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

评论(3

遮了一弯 2024-12-06 07:23:36

听起来您想使用自定义启动脚本。启动脚本告诉 erlang 系统要启动什么。在您使用的脚本中,您使用以下命令设置引导脚本:

-boot start_sasl

http:// www.erlang.org/doc/system_principles/system_principles.html,查找“用户定义的启动脚本”部分

一个更简单的选择可能是将您的应用程序转换为使用 rebar:https://github.com/basho/rebar。然后,您将能够执行以下操作:

./rebar compile generate

这将为应用程序创建一个版本,然后您可以:

./rel/<app_name>/bin/<app_name>

相同的原则,只是全部打包以便于使用。

Sounds like you want to use a custom boot script. A boot script tells the erlang system what to start. In the script you're using, you're setting the boot script with:

-boot start_sasl

http://www.erlang.org/doc/system_principles/system_principles.html, look for the section "User-Defined Boot Scripts"

An easier option may be to convert your application to use rebar: https://github.com/basho/rebar. You would then be able to do the following:

./rebar compile generate

This will create a release for the application, allowing you to then:

./rel/<app_name>/bin/<app_name>

Same principles, just all wrapped up for easy use.

晒暮凉 2024-12-06 07:23:36

添加参数-detached文档很好地总结了这一点:

启动与系统控制台分离的 Erlang 运行时系统。对于运行守护进程和后台进程很有用。

完成此操作后,您就可以使用 -s 参数启动应用程序。假设 $NAME = myapp,init 将尝试调用 myapp:start/0 (如果需要,您可以自定义它)。该函数应以调用 application:start(myapp) 结束。

如果您能将所有这些拼图拼凑到位,那么您应该有一个可行的脚本。

Add the parameter -detached. The documentation summarizes this nicely:

Starts the Erlang runtime system detached from the system console. Useful for running daemons and backgrounds processes.

Once you do that, you can get your application to start with the -s parameter. Assuming $NAME = myapp, init will attempt to call myapp:start/0 (you can customize this if you want). That function should end with a call to application:start(myapp).

If you can get all of those puzzle pieces in place, you should have a working script.

锦欢 2024-12-06 07:23:36

好吧,您可以尝试将其连接到 Apache (请参阅此处),或者一个不像屏幕会话那么麻烦的简单解决方案是使用 nohup。如果您实际上是在生产服务器上实现这一点,并且不想采用 Apache 路线,您可能会考虑 初始化脚本

Well, you could try hooking it in to Apache (see here), or a simple solution that's not quite as hacky as screen sessions is to use nohup. If you're actually implementing this on a production server, and don't want to take the Apache route, you might consider an init script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文