将 erlang shell 作为守护进程/服务运行
显然,我有一个在 Erlang shell 中运行的 Erlang 程序,我想监视它。
这就是我想要的:
- 当机器启动时,Erlang shell 应该随之启动,并且在 shell 中运行的程序也应该随之启动。
- 如果 Erlang shell 由于某种原因崩溃,它应该重新启动。
- 您应该能够手动启动/停止/重新启动 Erlang shell。
示例:
/etc/init.d/foobar start
/etc/init.d/foobar stop
/etc/init.d/foobar restart
我还没有开始处理整个“如果崩溃就重新启动”的事情,我被简单的事情困住了,或者这很容易吗?
我所做的是这样的:
从 /etc/init.d/sculpture 中获取骨架代码并替换 PATH、DESC、NAME 等...这有效,我可以做:
/etc/init.d/foobar start
但是,我无法阻止它...事情是我用“erl”启动 Erlang shell,这是一个脚本,它做了一些我不理解的奇特的事情。它所做的一件事是,它创建一个非常长且复杂的进程名称。它不仅仅是“erl”,它就像:
/usr/lib/erlang/erts-5.7.4/bin/beam.smp -- -root /usr/lib/erlang -progname erl -- -home /home/xxx -- ....还有更多。
有更好的方法吗?
操作系统:Ubuntu 11.04
I have an Erlang program that runs in Erlang shell, obviously, and I want to monitor it.
This is what I want:
- When the machine starts the Erlang shell should start up with it, and the program that runs in the shell too.
- If the Erlang shell crashes for some reason it should get restarted.
- You should be able to manually start/stop/restart the Erlang shell.
Example:
/etc/init.d/foobar start
/etc/init.d/foobar stop
/etc/init.d/foobar restart
I haven't started with the whole "restart itself if crash" thing yet, got stuck with the easy thing, or is it easy?
What I have done is this:
Taken the skeleton code from /etc/init.d/skeleton and replaced the PATH, DESC, NAME etc etc... This works, I can do:
/etc/init.d/foobar start
However, I cant stop it... The thing is that I start the Erlang shell with "erl" which is a script that does some fancy things that I dont understand. One thing it does is, it creates a very long and complex process name. It's not just "erl" it's like:
/usr/lib/erlang/erts-5.7.4/bin/beam.smp -- -root /usr/lib/erlang -progname erl -- -home /home/xxx -- .... and some more.
Is there a better way to do this?
OS: Ubuntu 11.04
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
除了创建目标版本(@Martin 推荐的标准 Erlang 生产环境)之外,您还需要以下内容:
要允许自动重新启动崩溃的节点,您应该使用 心脏功能。
要停止正在运行的 Erlang 节点,您可以启动一个临时 Erlang 节点,连接到正在运行的节点并发出停止命令:
noshell
禁用输入和 shell 输出sname
设置临时节点的名称eval
让您执行任何有效的 Erlang 表达式rpc:call(Node, M, F, A)
将在指定节点 (A
) 上调用M:F(A)
是将作为实参传递给函数的参数列表)s M F
运行函数M:F()
(
eval
和s
按顺序运行)In addition to creating a target release, a standard Erlang production environment as recommended by @Martin, you need the following:
To allow for automatic restart of a crashed node, you should use the heart functionality.
To stop a running Erlang node, you could start up a temporary Erlang node, connect to the running node and issue a stop command:
noshell
disables input and shell outputsname
sets the name for the temporary nodeeval
let's you execute any valid Erlang expressionrpc:call(Node, M, F, A)
will callM:F(A)
on the node specified (A
is list of arguments that will be passed to the function as real arguments)s M F
runs the functionM:F()
(
eval
ands
are run in sequence)您想要做的是创建一个目标系统。这样做的文档在这里: http://www.erlang.org/doc/system_principles /create_target.html
然而,一开始有点复杂,直到您掌握基本概念为止。
粗略地说,您将执行以下操作:
然后可以将其作为一项服务进行管理,包括重新启动/监视器以及您想要添加的任何内容。
What you want to do is create a target-system. The documentation for doing so is here: http://www.erlang.org/doc/system_principles/create_target.html
However, it is a bit complicated at first, until you get the basic concepts.
Roughly speaking, you do the following:
This can then be managed as a service with restarts/monitors and whatever you like to add.
最近发布的 erld 项目是真正守护 Erlang 应用程序的绝佳方法。它为守护程序应执行的所有操作提供支持,即:
请参阅此处的 github 页面:https://github.com/ShoreTel-公司/erld
The recently released erld project is an excellent way of truly daemonising an Erlang application. It provides support for all things a daemon should do, namely:
See their github page here: https://github.com/ShoreTel-Inc/erld