Reputation: 511
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. 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. I have set the path in the .erlang file with
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. 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
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). 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. 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.
Thanks for any help.
ADDED: not sure it helps, I add the erlang app code as well
{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. Making [] [] to be seen as [[],[]].
Upvotes: 2
Views: 828
Reputation: 511
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. Therefore, I have solved my problem by using the application as such and execute on command line
erl (options) eval "application:start(...)"
Upvotes: 3
Reputation: 61
Yes according to http://erlang.org/doc/man/init.html the funtion that run executes should be of arity 1. You could define init([Application, Type])
which calls start/2 and then run using erl -run wotsuke_geolocation_lookup_server init [] []
Upvotes: 1