自动重启 Erlang 应用程序

发布于 2024-09-06 01:45:04 字数 646 浏览 7 评论 0原文

我最近遇到了一个错误,整个 Erlang 应用程序死掉了,产生了一条如下所示的日志消息:

=INFO REPORT==== 11-Jun-2010::11:07:25 ===
     application: myapp
     exited: shutdown
     type: temporary

我不知道是什么触发了这次关闭,但我遇到的真正问题是它没有自行重新启动。相反,现在空的 Erlang 虚拟机只是坐在那里什么都不做。

现在,根据我所做的研究,您似乎可以为应用程序提供其他“启动类型”:“瞬态”和“永久”。

如果我在应用程序中启动一个 Supervisor,我可以告诉它使一个特定进程暂时或永久,并且它会自动为我重新启动它。但是,根据文档,如果我将一个应用程序设置为暂时或永久,它在死亡时不会重新启动它,而是会杀死所有其他应用程序。

我真正想做的是以某种方式告诉 Erlang VM 某个特定的应用程序应该始终运行,如果它出现故障,请重新启动它。这可以吗?

(我不是在谈论在我的应用程序之上实现一个主管,因为这样就存在一个问题 22:如果我的主管进程崩溃怎么办?我正在寻找某种 API 或设置,我可以使用它来让 Erlang 监视器和为我重新启动我的应用程序。)

谢谢!

I recently ran into a bug where an entire Erlang application died, yielding a log message that looked like this:

=INFO REPORT==== 11-Jun-2010::11:07:25 ===
     application: myapp
     exited: shutdown
     type: temporary

I have no idea what triggered this shutdown, but the real problem I have is that it didn't restart itself. Instead, the now-empty Erlang VM just sat there doing nothing.

Now, from the research I've done, it looks like there are other "start types" you can give an application: 'transient' and 'permanent'.

If I start a Supervisor within an application, I can tell it to make a particular process transient or permanent, and it will automatically restart it for me. However, according to the documentation, if I make an application transient or permanent, it doesn't restart it when it dies, but rather it kills all the other applications as well.

What I really want to do is somehow tell the Erlang VM that a particular application should always be running, and if it goes down, restart it. Is this possible to do?

(I'm not talking about implementing a supervisor on top of my application, because then it's a catch 22: what if my supervisor process crashes? I'm looking for some sort of API or setting that I can use to have Erlang monitor and restart my application for me.)

Thanks!

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

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

发布评论

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

评论(3

鹿港小镇 2024-09-13 01:45:05

您应该能够在顶级管理程序中修复此问题:设置重新启动策略以允许每秒重新启动一百万次,并且应用程序永远不会崩溃。类似于:(

init(_Args) ->
    {ok, {{one_for_one, 1000000, 1},
          [{ch3, {ch3, start_link, []},
            permanent, brutal_kill, worker, [ch3]}]}}.

示例改编自 OTP 设计原则用户指南。)

You should be able to fix this in the top-level supervisor: set the restart strategy to allow one million restarts every second, and the application should never crash. Something like:

init(_Args) ->
    {ok, {{one_for_one, 1000000, 1},
          [{ch3, {ch3, start_link, []},
            permanent, brutal_kill, worker, [ch3]}]}}.

(Example adapted from the OTP Design Principles User Guide.)

永言不败 2024-09-13 01:45:05

如果虚拟机出现故障,您可以使用 heart 重新启动整个虚拟机,然后使用永久应用程序键入以确保应用程序退出时 VM 也退出。

最终,您需要在应用程序之上信任一些东西,无论是管理进程、erlang VM 还是您编写的某些 shell 脚本 - 如果它也发生失败,那将始终是一个问题。

You can use heart to restart the entire VM if it goes down, then use a permanent application type to make sure that the VM exits when your application exits.

Ultimately you need something above your application that you need to trust, whether it is a supervisor process, the erlang VM, or some shell script you wrote - it will always be a problem if that happens to fail also.

你与昨日 2024-09-13 01:45:05

使用 Monit,然后将应用程序设置为通过使用整个应用程序的主管以合理的重新启动频率来终止。如果应用程序终止,VM 也会终止,并且 monit 会重新启动所有内容。

我永远无法让 Heart 足够可靠,因为它只重新启动虚拟机一次,而且它不能很好地处理 erlang 虚拟机的kill -9。

Use Monit, then setup your application to terminate by using a supervisor for the whole application with a reasonable restart frequency. If the application terminates, the VM terminates, and monit restarts everything.

I could never get Heart to be reliable enough, as it only restarts the VM once, and it doesn't deal well with a kill -9 of the erlang VM.

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