erlang 如何获取更多关于启动Inets httpd时出错的信息?

7uzetpgm  于 2022-12-08  发布在  Erlang
关注(0)|答案(4)|浏览(334)

我用以下代码启动了Inets http:

> inets:start(httpd, [{port, 8060}, {server_name, "myserver"},
> {server_root, "/Users/jonas/code"},                         
> {document_root, "/Users/jonas/code/mydocs"},             
> {bind_address, {192, 168, 2, 5}}]).                         
{error,inets_not_started}

所以我唯一的错误信息是{error,inets_not_started}。有没有办法让我得到更多关于哪里出错的信息?

nkkqxpd9

nkkqxpd91#

First, to solve your problem just start inets application (error reason indicates it is not started) by:

inets:start().

Second, in general starting SASL application improves a bit readability of Erlang/OTP errors/crashes - but it is not the case here.

z9zf31ra

z9zf31ra2#

您必须先呼叫inets:start/0。如需详细信息,请参阅the inets documentation

gijlo24d

gijlo24d3#

启动(服务、服务配置、如何)-〉{确定、Pid}|{错误,原因}

Dynamically starts an inets service after the inets application has been started.

所以你需要先调用这个函数。
启动()-〉启动(类型)-〉确定|{错误,原因}
类型:类型=永久|瞬变的|临时的

Starts the Inets application.
ioekq8ef

ioekq8ef4#

This is a great question because of the unfortunate overloading of the inets:start/[0,1,2,3] function and the httpc documentation isn't very clear that starting inets will automatically start the httpc service as well.
Especially when on simply jumps to the HTTP CLIENT SERVICE START/STOP section to get started quickly, thus missing the note in the module description.

  • inets:start/[0,1] starts the inets application itself and the httpc service with the default profile called default (this is only documented in httpc ).
  • inets:start/[2,3] (which should be called start_service) starts one of the services that can run atop inets (viz. ftpc , tftp , httpc , httpd ) once the inets application has already started.

start() ->
start(Type) -> ok | {error, Reason}
Starts the Inets application.
start(Service, ServiceConfig) -> {ok, Pid} | {error, Reason}
start(Service, ServiceConfig, How) -> {ok, Pid} | {error, Reason}
Dynamically starts an Inets service after the Inets application has been started
    (with inets:start/[0,1]).

Note regarding httpc

From the top of the httpc module documentation :
When starting the Inets application, a manager process for the default profile is started. The functions in this API that do not explicitly use a profile accesses the default profile.
That is, the httpc service will automatically get started using the default profile called default .

1> inets:start().
ok
2> httpc:get_options(all, default).
{ok,[{proxy,{undefined,[]}},
     {https_proxy,{undefined,[]}},
     {pipeline_timeout,0},
     {max_pipeline_length,2},
     {max_keep_alive_length,5},
     {keep_alive_timeout,120000},
     {max_sessions,2},
     {cookies,disabled},
     {verbose,false},
     {ipfamily,inet},
     {ip,default},
     {port,default},
     {socket_opts,[]},
     {unix_socket,undefined}]}
3>
3> inets:start(httpc, [{profile, lofa}]).
{ok,<0.95.0>}
4>
5> httpc:get_options(all, default).
{ok,[...]}
6> httpc:get_options(all, lofa).
{ok,[...]}

Interestingly, when using a non-existing profile, the error message is inets_not_started :

7> httpc:get_options(all, balabab).
{error,inets_not_started}

相关问题