将 erlang shell 作为守护进程/服务运行

发布于 2024-11-26 13:00:59 字数 806 浏览 0 评论 0原文

显然,我有一个在 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 技术交流群。

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

发布评论

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

评论(3

鲜肉鲜肉永远不皱 2024-12-03 13:00:59

除了创建目标版本(@Martin 推荐的标准 Erlang 生产环境)之外,您还需要以下内容:

  • 要允许自动重新启动崩溃的节点,您应该使用 心脏功能

  • 要停止正在运行的 Erlang 节点,您可以启动一个临时 Erlang 节点,连接到正在运行的节点并发出停止命令:

    erl -noshell -sname temp_control \
        -eval "rpc:call(mynode@myhost, init, stop, [])" \
        -s 初始化停止
    
    • noshell 禁用输入和 shell 输出
    • sname 设置临时节点的名称
    • eval 让您执行任何有效的 Erlang 表达式
      • rpc:call(Node, M, F, A) 将在指定节点 (A) 上调用 M:F(A)是将作为实参传递给函数的参数列表)
    • s M F 运行函数 M:F()

    evals 按顺序运行)

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:

    erl -noshell -sname temp_control \
        -eval "rpc:call(mynode@myhost, init, stop, [])" \
        -s init stop
    
    • noshell disables input and shell output
    • sname sets the name for the temporary node
    • eval let's you execute any valid Erlang expression
      • rpc:call(Node, M, F, A) will call M: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 function M:F()

    (eval and s are run in sequence)

泅人 2024-12-03 13:00:59

您想要做的是创建一个目标系统。这样做的文档在这里: http://www.erlang.org/doc/system_principles /create_target.html
然而,一开始有点复杂,直到您掌握基本概念为止。

粗略地说,您将执行以下操作:

  1. 创建一个空节点。即“bin、erts 和releases”目录(bin 中包含更新的脚本)。
  2. 按照 dox 中的描述,通过release_tools 创建一个版本。
  3. 在空节点上解压release,设置release/start_erl.data指向新的release和erts版本。

然后可以将其作为一项服务进行管理,包括重新启动/监视器以及您想要添加的任何内容。

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:

  1. Create an empty node. That is, the 'bin, erts and releases' directories (with updated scripts in bin).
  2. Create a release via release_tools as described in the dox.
  3. Unpack the release on the empty node, set the release/start_erl.data to point to the new release and erts versions.

This can then be managed as a service with restarts/monitors and whatever you like to add.

情定在深秋 2024-12-03 13:00:59

最近发布的 erld 项目是真正守护 Erlang 应用程序的绝佳方法。它为守护程序应执行的所有操作提供支持,即:

  • 可以从 init 脚本启动/停止
  • 启动时,控制权不会返回到控制台,直到程序成功启动(或启动失败)。
  • 启动诊断信息可以打印到控制台以指示进度,但一旦守护程序运行,输出就会停止。
  • 返回控制台时,返回代码指示成功 (0) 或失败(其他数字)。
  • 可以通过发送 SIGHUP 来触发日志轮换,

请参阅此处的 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:

  • Can be started/stopped from an init script
  • On startup, control does not return to the console until the program has successfully started (or failed to do so).
  • Startup diagnostic information can be printed to the console to indicate progress, but output ceases once the daemon is running.
  • On returning to the console, the return code indicates success (0) or failure (some other number).
  • Log rotation can be triggered by sending a SIGHUP

See their github page here: https://github.com/ShoreTel-Inc/erld

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