[erlang-questions] How to force kernel application will always be started before my app

Sergey A. n39052@REDACTED
Sun Nov 23 18:33:07 CET 2008


I've a tricky problem with starting my OTP application from escript interface.

Here is what I do in escript to start my app:

First I start a node for my application:

RunNode = "erl -detached -sname foo@REDACTED -setcookie my_cookie
-boot start_sasl -config log -pa /path/to/ebin",

Then my script waits until the node is actually started:

wait_for(pong, foo@REDACTED),

after that I do rpc:call to start my application and check if there
was an error (that is why I don't use "erl -s foo start". I need to
know in my escript whether app was started or not):

case rpc:call(foo@REDACTED, foo, start, []) of
        ok -> ok;
        {error, Reason} ->

But at some computers such a rpc:call fails with {error,
{not_started,kernel}} return value. This happens because kernel
application doesn't have enough time between os:cmd and rpc:call calls
to start.

What I should do to avoid this error in a right manner?

I think that using of timer:sleep(300) isn't the right way.

I could use somethin like

[rpc:call(foo@REDACTED, application, start, [App]) || App <- [kernel, sasl]]

in escript before starting my application, but it looks like a hack
(or not?). I beleive there should be the standard way to ensure that
all the dependencies of my app were already started.

It's my foo.app:

{application, foo,
 [{description, "Foo"},
  {vsn, "1.0"},
  {modules, [<skipped>]},
  {registered, [foo_storage, foo_sup, foo_web]},
  {applications, [kernel, stdlib, sasl]},
  {mod, {gin_app, []}}



More information about the erlang-questions mailing list