如何停止第三方Erlang应用程序
我正在编写我的第一个 erlang 应用程序,但我还不了解 erlang 生态系统的某些部分以及应该如何在其中完成工作。例如,如果我的应用程序依赖于其他一些应用程序,如何立即和停止它们?实际上,我已经弄清楚如何启动,只需将 application:start/1
调用放入应用程序模块的 start/2
函数中即可:
-module(myapp).
-behaviour(application).
-export([start/0, start/2, stop/1]).
start(_Type, _StartArgs) ->
ok = application:start(ssl),
ok = application:start(inets),
ok = application:start(log4erl),
myapp_sup:start_link().
stop(_State) ->
ok.
但是当我尝试将相应的 application:stop/1
调用 myapp:stop/1
函数并从 erlang shell application:stop(myapp)
稍后调用只是停止响应任何命令。
I am in the process of writing my first erlang application and I don't understand yet some parts of the erlang ecosystem and how things should be done in it. For example if my app depends on some other apps what is the way to start and stop them at once ? Actually, I've figured out how to start, just put application:start/1
calls in the start/2
function of the application module:
-module(myapp).
-behaviour(application).
-export([start/0, start/2, stop/1]).
start(_Type, _StartArgs) ->
ok = application:start(ssl),
ok = application:start(inets),
ok = application:start(log4erl),
myapp_sup:start_link().
stop(_State) ->
ok.
But when I tried to put corresponding application:stop/1
calls into the myapp:stop/1
function and called from the erlang shell application:stop(myapp)
the later just stopped responding to any command.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
阅读官方文档:
更多信息此处和那里。
通常,当我有一些依赖应用程序时,我会使用 .app 资源文件,其中列出了我的应用程序需要启动(或加载)才能正常工作的所有应用程序。
Reading from the official doc:
More information here and there.
Usually, when I have some dependent applications, I use a .app resource file, where I list all applications that need to be started (or loaded) by my application to work correctly.
我建议查看 erlware.org 并使用 sinan 和faxien 工具进行 Erlang 开发。如果您坚持对您的应用程序严格遵守 OTP 合规性并发布它,它不仅会使开发变得更容易且不易出错,而且使共享您的应用程序变得更加容易。即将出版的书http://www.manning.com/logan/回答了更多,你可以阅读 pdf 格式的早期副本。
在模块中“随机”放置开始和停止是一个坏主意。
I suggest checking out erlware.org and using the tools sinan and faxien for your Erlang development. If you stick to strict OTP compliance for your apps and releases it not only makes development easier and less error prone but it makes sharing your apps much much easier. The upcoming book http://www.manning.com/logan/ answers much more, you can read an early copy in pdf form.
Putting starts and stops "randomly" in your modules is a bad idea.
您已经得到了一些好的建议。让我对您所看到的问题添加一个解释:您的
stop
回调函数由应用程序控制器同步调用,即,应用程序控制器在您的函数返回之前不会执行任何其他操作。但是您要求应用程序控制器停止其他一些应用程序,这两个进程就陷入死锁,互相等待。You already got some good suggestions. Let me just add an explanation of the problem you're seeing: your
stop
callback function is called synchronously by the application controller, i.e., the application controller will not do anything else until your function returns. But you ask the application controller to stop some other applications—and the two processes are in a deadlock, waiting for each other.