Init terminating in do_boot - distillery migrations

I’m trying to have migrations automatically configured to be setup in the build and production servers as mentioned in https://hexdocs.pm/distillery/1.5.2/running-migrations.html
The module, the command and the configuration were done.

In the build server, after successful build, when tried to run bin/myapp migrate it failed.
Read this topic made the change me = :orif in the above mentioned module, as suggested but it is not possible to migrate.
The error is:

{"init terminating in do_boot",{{badmatch,{error,{already_loaded,orif}}},[{'Elixir.Orif.ReleaseTasks',seed,0,[{file,"lib/orif/release_tasks.ex"},{line,20}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}                                                                        
init terminating in do_boot ()
Crash dump is being written to: erl_crash.dump...done

Read elsewhere that this could happen because of different versions of elixir and erlang.
In fact, my development is done in Linux with:


Elixir 1.7.3 (compiled with Erlang/OTP 21)

and my build box is FreeBSD running:

Elixir 1.7.3 (compiled with Erlang/OTP 19)

Installed the erlang-runtime21: 21.1 package, modified the PATH to have access to the new installed runtime:

Elixir 1.7.3 (compiled with Erlang/OTP 19)

and

Eshell V10.1  (abort with ^G)
"21"

But the same error is daunting me.

What to do to solve this issue?

The OTP version doesn’t seem to be an issue according to the error message, for me it seems as if you were starting your application twice when it should be started only once.

As I’m not using distillery, I can’t give you much more hints, but you probably need to reveal a bit of your distillery config/scripts.

I’m just curious, any special reason not using distillery 2?

Nice point indeed… I’m using 2.0.10, but read the documentation that first appeared in my search and didn’t take notice of the version.
Will try it later with the modified configuration for migrations.

I’ve updated the scripts to the newest 2.0.10 version, as mentioned in https://hexdocs.pm/distillery/2.0.10/guides/running_migrations.html

I’ve created the orif_dev and orif_prod databases in the build machine.

When running ./_build/prod/rel/orif/bin/orif migrate in the build box, get this error:

** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started```

ok.  So I start the application with:
```$ ./_build/prod/rel/orif/bin/orif foreground                                         
22:55:54.510 [info] Running OrifWeb.Endpoint with Cowboy using http://0.0.0.0:8048                                       
22:55:54.511 [error] Could not find static manifest at "/usr/home/lupe/orif/orif_build/_build/prod/rel/orif/lib/orif-0.0.1/priv/static/cache_manifest.json". Run "mix phx.digest" after building your static files or remove the configuration from "config/prod.exs".```

In another virtual terminal, try again:

```$ ./_build/prod/rel/orif/bin/orif migrate                                            
** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
    (stdlib) gen.erl:261: :gen.do_for_proc/2
    (stdlib) gen_event.erl:197: :gen_event.rpc/2
    (artificery) lib/console.ex:270: Artificery.Console.init/0                                                           
    (distillery) lib/entry.ex:42: Mix.Releases.Runtime.Control.main/1                                                    
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:232: Code.eval_string/3```

What should I do differently?

It would be helpful if you could share any distillery related codes here. I have successfully deployed one of my project https://github.com/chenxsan/telegram-bot-for-twitter/blob/master/lib/release_tasks.ex with distillery 2 according to the documentation, so it could be some faults in your configurations.

My script is similar to yours, just changing the two lines with the app name.

For the first build, I did this

  1. [devel machine] run $ mix edeliver build release
  2. [build machine] create the app_dev and app_prod database
  3. [bm] ./_build/prod/rel/orif/bin/orif foreground
  4. [bm] ./_build/prod/rel/orif/bin/orif migrate (at another terminal)

Is this procedure correct? Am I missing something or is something out of order?

Your application can’t start because of missing files, please read the error message given and provide the files that phoenix asks for or remove them from the config.

I’ve overcome the missing files issue, I think, that were related to producing static files, but still can’t run the migrations in the production host.

In the build machine:

11:43:59.506 [info] Running OrifWeb.Endpoint with Cowboy using http://127.0.0.84:8084
11:46:39.104 [info] GET /contacts/new
11:46:39.108 [info] Sent 200 in 4ms
12:02:45.098 [info] GET /
12:02:45.098 [info] Sent 200 in 639_s
12:02:55.757 [info] GET /
12:02:55.758 [info] Sent 200 in 344_s
12:13:18.679 [info] GET /
12:13:18.680 [info] Sent 200 in 701_s

seems fine, but the migrations raise some problem:

$ ./bin/orif migrate
** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started                                                                                                                   
    (stdlib) gen.erl:261: :gen.do_for_proc/2
    (stdlib) gen_event.erl:197: :gen_event.rpc/2
    (artificery) lib/console.ex:270: Artificery.Console.init/0
    (distillery) lib/entry.ex:42: Mix.Releases.Runtime.Control.main/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:232: Code.eval_string/3

Tried it from the development machine using edeliver:

$ mix edeliver start production --verbose

EDELIVER ORIF WITH START COMMAND

-----> starting production servers

production node:

  user    : elixir
  host    : orif_orif
  path    : /usr/home/elixir/orif/orif_release
  response: ** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started                                                                                                       
    (stdlib) gen.erl:261: :gen.do_for_proc/2
    (stdlib) gen_event.erl:197: :gen_event.rpc/2
    (artificery) lib/console.ex:270: Artificery.Console.init/0
    (distillery) lib/entry.ex:42: Mix.Releases.Runtime.Control.main/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:232: Code.eval_string/3
** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started                                                                                                                   
    (stdlib) gen.erl:261: :gen.do_for_proc/2
    (stdlib) gen_event.erl:197: :gen_event.rpc/2
    (artificery) lib/console.ex:270: Artificery.Console.init/0
    (distillery) lib/entry.ex:42: Mix.Releases.Runtime.Control.main/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:232: Code.eval_string/3
** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started                                                                                                                   
    (stdlib) gen.erl:261: :gen.do_for_proc/2
    (stdlib) gen_event.erl:197: :gen_event.rpc/2
    (artificery) lib/console.ex:270: Artificery.Console.init/0
    (distillery) lib/entry.ex:42: Mix.Releases.Runtime.Control.main/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:232: Code.eval_string/3


START DONE!

and when trying to run migrations from the development machine:

$ mix edeliver migrate production --verbose                                                                                                                                                                                              

EDELIVER ORIF WITH MIGRATE COMMAND

-----> migrateing production servers

production node:

  user    : elixir
  host    : orif_orif
  path    : /usr/home/elixir/orif/orif_release
  response: ** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started                                                                                                       
    (stdlib) gen.erl:261: :gen.do_for_proc/2
    (stdlib) gen_event.erl:197: :gen_event.rpc/2
    (artificery) lib/console.ex:270: Artificery.Console.init/0
    (distillery) lib/entry.ex:42: Mix.Releases.Runtime.Control.main/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:232: Code.eval_string/3
** (exit) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started                                                                                                                   
    (stdlib) gen.erl:261: :gen.do_for_proc/2
    (stdlib) gen_event.erl:197: :gen_event.rpc/2
    (artificery) lib/console.ex:270: Artificery.Console.init/0
    (distillery) lib/entry.ex:42: Mix.Releases.Runtime.Control.main/1
    (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
    (elixir) lib/code.ex:232: Code.eval_string/3

@chensan My release_tasks.ex file is identical to yours, except for the name of the application.

This is my first deployment and it’s been very difficult to set all this up.

You dont need to run bin/orif/ foregound or bin/orif start. You only need run your task. In my case, I have this task

defmodule ContentProxy.ReleaseTasks do
  @otp_app :content_proxy

  defp init(app) do
    IO.puts "Starting dependencies.."
    {:ok, _} = Application.ensure_all_started(app)
  end

  def seed do
    init(@otp_app)

    seed_data = seed_file_path(@otp_app)
      |> File.read!()
      |> Jason.decode!()

    Enum.each seed_data, fn(content) ->
      ContentProxy.Resources.create_content(content)
      IO.puts("DOCUMENT #{content["name"]} INSERTED")
    end

    stop()
  end

  defp seed_file_path(app),
    do: priv_dir(app, ["seed_data", "contents.json"])

  defp priv_dir(app, path) when is_list(path) do
    case :code.priv_dir(app) do
      priv_path when is_list(priv_path) or is_binary(priv_path) ->
        Path.join([priv_path] ++ path)

      {:error, :bad_name} ->
        raise ArgumentError, "unknown application: #{inspect app}"
    end
  end

  defp stop do
    IO.puts "Success!"
    :init.stop()
  end

end

inside of the terminal session, I run my task typing _build/prod/rel/content_proxy/bin/content_proxy command "Elixir.ContentProxy.ReleaseTasks" seed and its works like a charm!

It is worth noting {:ok, _} = Application.ensure_all_started(app) already start to you all children process that you’ve configured in application.ex

I’ve notice that if I run the app with start or foreground before run command, when I run command "Elixir.ContentProxy.ReleaseTasks" seed I get the following error:

22:01:18.737 [error] Failed to start Ranch listener ContentProxyWeb.Endpoint.HTTP in :ranch_tcp:listen([{:cacerts, :...}, {:key, :...}, {:cert, :...}, :inet6, {:port, 4000}]) for reason :eaddrinuse (address already in use)

22:01:18.759 [info] Application content_proxy exited: ContentProxy.Application.start(:normal, []) returned an error: shutdown: failed to start child: ContentProxyWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, ContentProxyWeb.Endpoint.HTTP}
        ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
            ** (EXIT) {:listen_error, ContentProxyWeb.Endpoint.HTTP, :eaddrinuse}
22:01:18.762 [info] Application mongodb exited: :stopped
22:01:18.772 [info] Application db_connection exited: :stopped
22:01:18.772 [info] Application connection exited: :stopped
22:01:18.773 [info] Application gettext exited: :stopped
22:01:18.773 [info] Application poolboy exited: :stopped
22:01:18.773 [info] Application absinthe_relay exited: :stopped
22:01:18.773 [info] Application jason exited: :stopped
22:01:18.774 [info] Application atomic_map exited: :stopped
22:01:18.774 [info] Application absinthe_plug exited: :stopped
22:01:18.774 [info] Application absinthe exited: :stopped
22:01:18.774 [info] Application phoenix exited: :stopped
22:01:18.775 [info] Application eex exited: :stopped
22:01:18.775 [info] Application phoenix_pubsub exited: :stopped
22:01:18.775 [info] Application distillery exited: :stopped
22:01:18.776 [info] Application runtime_tools exited: :stopped
22:01:18.776 [info] Application artificery exited: :stopped
22:01:18.777 [info] Application plug_cowboy exited: :stopped
22:01:18.777 [info] Application cowboy exited: :stopped
22:01:18.777 [info] Application cowlib exited: :stopped
22:01:18.778 [info] Application ranch exited: :stopped
22:01:18.778 [info] Application ssl exited: :stopped
22:01:18.778 [info] Application public_key exited: :stopped
22:01:18.779 [info] Application asn1 exited: :stopped
22:01:18.779 [info] Application phoenix_ecto exited: :stopped
22:01:18.779 [info] Application plug exited: :stopped
22:01:18.780 [info] Application mime exited: :stopped
22:01:18.780 [info] Application plug_crypto exited: :stopped
22:01:18.780 [info] Application ecto exited: :stopped
=INFO REPORT==== 27-Jan-2019::22:01:18.817574 ===
    application: logger
    exited: stopped
    type: temporary
{"init terminating in do_boot",{{badmatch,{error,{content_proxy,{{shutdown,{failed_to_start_child,'Elixir.ContentProxyWeb.Endpoint',{shutdown,{failed_to_start_child,{ranch_listener_sup,'Elixir.ContentProxyWeb.Endpoint.HTTP'},{shutdown,{failed_to_start_child,ranch_acceptors_sup,{listen_error,'Elixir.ContentProxyWeb.Endpoint.HTTP',eaddrinuse}}}}}}},{'Elixir.ContentProxy.Application',start,[normal,[]]}}}}},[{'Elixir.ContentProxy.ReleaseTasks',init,1,[{file,"lib/content_proxy/release_tasks.ex"},{line,7}]},{'Elixir.ContentProxy.ReleaseTasks',seed,0,[{file,"lib/content_proxy/release_tasks.ex"},{line,16}]},{init,start_em,1,[]},{init,do_boot,3,[]}]}}
init terminating in do_boot ({{badmatch,{error,{content_proxy,{_}}}},[{Elixir.ContentProxy.ReleaseTasks,init,1,[{_},{_}]},{Elixir.ContentProxy.ReleaseTasks,seed,0,[{_},{_}]},{init,start_em,1,[]},{init

Crash dump is being written to: erl_crash.dump...done