简体   繁体   English

从命令行启动erlang应用程序时出现问题

[英]Problems with starting an erlang application from the command line

I am trying to start an application form the command line. 我正在尝试从命令行启动应用程序。 The application is basically a OTP compliant TCP server and it works fine when started from the shell. 该应用程序基本上是OTP兼容的TCP服务器,并且从外壳启动时运行良好。 However, when started form the command line it actually does not start. 但是,从命令行启动时,它实际上不会启动。

I have all files in a compliant folder structure, meaning sources in \\src and binaries \\ebin. 我的所有文件都位于兼容的文件夹结构中,即\\ src和二进制文件\\ ebin中的源。 I have set the path in the .erlang file with 我已经在.erlang文件中设置了路径

code:add_patha("./ebin").

And the function that is being called is in this module 而被调用的功能在此模块中

-module(wotsuke_geolocation_lookup_server).
-behaviour(application).

-export([start/0, start/2, stop/1]).

start() -> 
    event_dbs:start(),
    wotsuke_server_sup:start_link().

start(_Type, _Args) ->
    event_dbs:start(),
    wotsuke_server_sup:start_link().

stop(_State) ->
    ok.

I have added (redundantly) also a start/0 (i use a start/2 due to future features requiring the args) because starting with arguments never worked. 我还(冗余地)添加了一个start / 0(由于将来的功能需要使用args,所以我使用了start / 2),因为以参数开头从未奏效。 Now when I run: 现在,当我运行时:

erl -run wotsuke_geolocation_lookup_server start [] []

I get 我懂了

Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

{"init terminating in do_boot",{undef,[{wotsuke_geolocation_lookup_server,start,[["[]","[]"]],[]},{init,start_it,1,[]},{init,start_em,1,[]}]}}

Crash dump is being written to: erl_crash.dump...done
init terminating in do_boot ()

Meaning it cannot find the module/function. 表示找不到模块/功能。 Therefore, I used the redundant start/0 因此,我使用了冗余启动/ 0

erl -run wotsuke_geolocation_lookup_server start

and get: 并获得:

Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V7.0  (abort with ^G)
1> 

Basically nothing is started (no process ID returned). 基本上什么都没有启动(没有返回进程ID)。 I tried to connect to the server and get the typical answer when the server is off. 我尝试连接到服务器,并在服务器关闭时得到典型的答案。 I also tried by forcing erl to the ebin folder with the -pa option. 我还通过使用-pa选项将erl强制到ebin文件夹来进行尝试。 Same as above. 同上。

As a this is the first time I am trying to run an erlang app from the command line (in order to demonize it), I am left clueless. 因为这是我第一次尝试从命令行运行erlang应用程序(以使其妖魔化),所以我一无所知。

Thanks for any help. 谢谢你的帮助。

ADDED: not sure it helps, I add the erlang app code as well 添加:不确定是否有帮助,我也添加了erlang应用程序代码

{application, wotsuke_geolocation_lookup_server,
   [{description, "Wotsuke Geolocation lookup server"},
    {vsn, "0.1.0"},
    {modules, [tcpserver_otp_backend, ets_methods, data_packing, data_formats, event_timings, logger, event_dbs,
                    obsolete_data_clean_ad, obsolete_data_clean, wotsuke_data_input, wotsuke_logger, wotsuke_server_sup, data_retrieve, wotsuke_data_output, user_event_dbs,
                    event_areas]},
    {registered, [wotsuke_data_input, wotsuke_server_sup, wotsuke_logger, wotsuke_data_output]},
    {applications, [kernel, stdlib, mnesia]},
    {env, []},
    {mod, {bsc, []}}]}.

UPDATE: One issue is solved. 更新:解决了一个问题。 The issue with the command 命令的问题

erl -run wotsuke_geolocation_lookup_server start [] []

is actually due t the fact that erl expects either a start/0 is only the module is specified or arity 1 if the function is also specified. 实际上是由于erl期望仅指定模块才开始/ 0或如果还指定了功能则为1的事实。 Making [] [] to be seen as [[],[]]. 使[] []被视为[[],[]]。

Clearly my problem is due to the fact that a supervisor cannot be started via the command line as a standard function but by using application:start. 显然,我的问题是由于无法通过命令行将管理员作为标准功能来启动,而是通过使用application:start来启动。 Therefore, I have solved my problem by using the application as such and execute on command line 因此,我已经通过使用该应用程序并在命令行上执行解决了我的问题

erl (options) eval "application:start(...)"

根据http://erlang.org/doc/man/init.html可以 ,运行执行的功能应为1。您可以定义init([Application, Type]) ,该函数调用start / 2,然后使用erl -run wotsuke_geolocation_lookup_server init [] []运行erl -run wotsuke_geolocation_lookup_server init [] []

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM