Erlang,如何加载具有依赖关系的应用程序 [英] Erlang, how to load applications with their dependencies

查看:333
本文介绍了Erlang,如何加载具有依赖关系的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的集群中有一些应用程序,我需要在不同的主机上启动一些应用程序。



故事是Erlang群集已经在运行,所以即使我每个应用程序都有.app资源文件,说明在我的之前应该启动哪些应用程序,这只能用于创建启动脚本,而不是在已经运行的节点中启动应用程序。



目前,我有一个自定义例程,使用应用程序:get_key(应用程序,应用程序)来提取依赖项,并在启动给定的应用程序之前单独启动它们。



我想知道是否没有更好的方法。

解决方案

脚本您首先需要启动依赖项。您可以构建智能手段来实现应用程序本身,以便在应用程序启动时,它将在需要之前启动任何所需的依赖关系。



我见过的一个地方这完成是在 Mochiweb 应用程序。默认的应用模板包含代码加载依赖启动:

  -module(some_app)。 
-export([start / 0,stop / 0])。

ensure_started(App) - >
案例应用程序:
的起始(应用程序)好的 - >
ok;
{error,{already_started,App}} - >
ok
结束。

%% @spec start() - > ok
%% @doc启动some_app服务器。
start() - >
some_app_deps:ensure(),
ensure_started(crypto),
应用程序:start(some_app)。

%% @spec stop() - > ok
%% @doc停止some_app服务器。
stop() - >
应用程序:stop(some_app)。


I have some apps in my cluster, I need to start some of them sometimes on different hosts.

The story is that the Erlang cluster is already running, so even though I have my .app resource file per application stating which applications should be started before mine, this only works to create a startup script, not to start an app in a already running node.

At the moment I have a custom routine that uses application:get_key(Application,applications) to extract the dependencies and start them separately before starting the given application.

I was wondering if there isn't a better way of doing this.

解决方案

When starting the app outside of the startup script you do need to start the dependencies first. You could build the smarts to do this into the app itself so that when the app starts it will start any required dependencies before it needs them.

One place I've seen this done is in Mochiweb apps. The default app templates include code for loading dependencies on startup:

-module(some_app).
-export([start/0, stop/0]).

ensure_started(App) ->
    case application:start(App) of
        ok ->
            ok;
        {error, {already_started, App}} ->
            ok
    end.

%% @spec start() -> ok
%% @doc Start the some_app server.
start() ->
    some_app_deps:ensure(),
    ensure_started(crypto),
    application:start(some_app).

%% @spec stop() -> ok
%% @doc Stop the some_app server.
stop() ->
    application:stop(some_app).

这篇关于Erlang,如何加载具有依赖关系的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆