我试图在一个erlang应用程序中创建两个webmachine实例。每个实例都要在不同的端口上运行,并有自己的特定配置。在webmachine 这里之后,我添加了以下要在主管规范(application_sup.erl)中启动的进程:
{
webmachine_instance_1,
{ webmachine_mochiweb, start,
[
[
{ ip, "0.0.0.0"},
{ port, 8000},
{ dispatch, [ {["*"], file_resource, []} ] }
]
]
},
permanent,
5000,
worker,
dynamic
},
{
webmachine_instance_2,
{ webmachine_mochiweb, start,
[
[
{ ip, "0.0.0.0"},
{ port, 8080},
{ dispatch, [ {["*"], file_resource, []} ] }
]
]
},
permanent,
5000,
worker,
dynamic
}当我包含这两个实例时,我会得到一个启动错误,无法启动我的erlang应用程序。在尝试使用webmachine的单个实例(webmachine_instance_1或webmachine_instance_2)运行应用程序之后,我的应用程序启动良好。
以下是具体的错误:
=PROGRESS REPORT==== 11-Mar-2014::17:00:31 ===
supervisor: {local, application_sup}
started: [{pid,<0.230.0>},
{name,webmachine_instance_1},
{mfargs,
{webmachine_mochiweb,start,
[[{ip,"0.0.0.0"},
{port,8000},
{dispatch, [{['*'],
file_resource,
[]
}]}]
]
}
},
{restart_type,permanent},
{shutdown,5000},
{child_type,worker}]
=SUPERVISOR REPORT==== 11-Mar-2014::17:00:31 ===
Supervisor: {local, application_sup}
Context: start_error
Reason: {'EXIT',
{undef,
[{webmachine_mochiweb,start,
[{ip,"0.0.0.0"},
{port,8080},
{dispatch,[{["*"],file_resource,[]}]}],
[]},
{supervisor,do_start_child,2,
[{file,"supervisor.erl"},{line,303}]},
{supervisor,start_children,3,
[{file,"supervisor.erl"},{line,287}]},
{supervisor,init_children,2,
[{file,"supervisor.erl"},{line,253}]},
{gen_server,init_it,6,
[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,
[{file,"proc_lib.erl"},{line,227}]}]}}
Offender: [{pid,undefined},
{name,webmachine_instance_2},
{mfargs,
{webmachine_mochiweb,start,
[{ip,"0.0.0.0"},
{port,8080},
{dispatch,[{["*"],file_resource,[]}]}]}},
{restart_type,permanent},
{shutdown,5000},
{child_type,worker}]我对erlang相当陌生,可能不太了解这里的基本问题--根据webmachine文档,我们应该能够启动相同应用程序的两个实例,但在erlang应用程序中有不同的配置。
谢谢你对这个问题的任何帮助/讨论!
发布于 2014-03-12 13:56:09
您的子进程配置应该具有以下形式:
{Name,
{webmachine_mochiweb, start, [WebConfig]},
permanent, 5000, worker, [mochiweb_socket_server]}其中,Name和WebConfig必须是您的and机器实例所特有的。WebConfig部件应该包括name和dispatch_group属性。例如:
WebConfig = [{name,instance1},
{dispatch_group,instance1},
{ip, Ip},
{port, Port},
{log_dir, "priv/log"},
{dispatch, Dispatch}],因此,对于多个实例,您可能有类似于主管规范的如下内容:
WebConfig1 = [{name,instance1},
{dispatch_group,instance1},
{ip, Ip},
{port, Port},
{log_dir, "priv/log"},
{dispatch, Dispatch}],
WebConfig2 = [{name,instance2},
{dispatch_group,instance2},
{ip, Ip},
{port, Port+1},
{log_dir, "priv/log"},
{dispatch, Dispatch}],
Web1 = {instance1,
{webmachine_mochiweb, start, [WebConfig1]},
permanent, 5000, worker, [mochiweb_socket_server]},
Web2 = {instance2,
{webmachine_mochiweb, start, [WebConfig2]},
permanent, 5000, worker, [mochiweb_socket_server]},
Processes = [Web1, Web2],
{ok, { {one_for_one, 10, 10}, Processes} }.另一件事:从问题中出现的名称application_sup判断,您可能已经运行了webmachine ./scripts/new_webmachine.sh,并将应用程序名指定为application。如果是这样,请不要这样做,因为application是一个关键的Erlang模块的名称,您的代码将与它发生冲突并导致各种问题。
https://stackoverflow.com/questions/22339530
复制相似问题