Erlang 在生产中启动应用程序
当我在本地主机上测试我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您想使用自定义启动脚本。启动脚本告诉 erlang 系统要启动什么。在您使用的脚本中,您使用以下命令设置引导脚本:
http:// www.erlang.org/doc/system_principles/system_principles.html,查找“用户定义的启动脚本”部分
一个更简单的选择可能是将您的应用程序转换为使用 rebar:https://github.com/basho/rebar。然后,您将能够执行以下操作:
这将为应用程序创建一个版本,然后您可以:
相同的原则,只是全部打包以便于使用。
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:
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:
This will create a release for the application, allowing you to then:
Same principles, just all wrapped up for easy use.
添加参数
-detached
。 文档很好地总结了这一点:完成此操作后,您就可以使用
-s
参数启动应用程序。假设$NAME
=myapp
,init 将尝试调用myapp:start/0
(如果需要,您可以自定义它)。该函数应以调用application:start(myapp)
结束。如果您能将所有这些拼图拼凑到位,那么您应该有一个可行的脚本。
Add the parameter
-detached
. The documentation summarizes this nicely:Once you do that, you can get your application to start with the
-s
parameter. Assuming$NAME
=myapp
, init will attempt to callmyapp:start/0
(you can customize this if you want). That function should end with a call toapplication:start(myapp)
.If you can get all of those puzzle pieces in place, you should have a working script.
好吧,您可以尝试将其连接到 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.