2

I have a simple phoenix application, and I tried to deploy it using exrm. The application works fine when I run it using

mix phoenix.start

But after building it using

mix release

(which finishes without error), running the executable returns an error:

rel/my_app/bin/my_app foreground

Exec: /home/ubuntu/projects/my_app/rel/my_app/erts-6.0/bin/erlexec -noshell -noinput +Bd -boot /home/ubuntu/projects/my_app/rel/my_app/releases/0.0.1/my_app -mode embedded -config /home/ubuntu/projects/my_app/rel/my_app/releases/0.0.1/sys.config -args_file /home/ubuntu/projects/my_app/rel/my_app/releases/0.0.1/vm.args -user Elixir.IEx.CLI -extra --no-halt +iex -- foreground
Root: /home/ubuntu/projects/my_app/rel/my_app
Erlang/OTP 17 [erts-6.0] [source-07b8f44] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

{"Kernel pid terminated",application_controller,"{application_start_failure,my_app,{bad_return,{{'Elixir.MyApp',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.MyApp',start,[normal,[]],[]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,272}]}]}}}}}"}

Crash dump was written to: erl_crash.dump
Kernel pid terminated (application_controller) ({application_start_failure,my_app,{bad_return,{{'Elixir.MyApp',start,[normal,[]]},{'EXIT',{undef,[{'Elixir.MyApp',start,[normal,[]],[]},{application

My mix.exs look like this:

defmodule MyApp.Mixfile do
  use Mix.Project

  def project do
    [ app: :my_app,
      version: "0.0.1",
      elixir: "~> 0.13.2",
      deps: deps ]
  end

  # Configuration for the OTP application
  def application do
    [
      mod: { MyApp, [] },
      applications: [:phoenix]
    ]
  end

  # Returns the list of dependencies in the format:
  # { :foobar, git: "https://github.com/elixir-lang/foobar.git", tag: "0.1" }
  #
  # To specify particular versions, regardless of the tag, do:
  # { :barbat, "~> 0.1", github: "elixir-lang/barbat" }
  defp deps do
    [
      {:phoenix, "0.2.4"},
      {:jazz, github: "meh/jazz", ref: "7af3b74e58eb1a3fc6b9874a2077efa420f6dfcc"},
      {:cowboy, github: "extend/cowboy", override: true, ref: "05024529679d1d0203b8dcd6e2932cc2a526d370"},
      #{ :redis, "1.1.0", [ github: "timbuchwaldt/elixir-redis"] },
      {:erlcloud,github: "gleber/erlcloud"},
      { :json,  github: "cblage/elixir-json" },
      { :amnesia, github: "uriagassi/amnesia" },
      { :exrm, "~> 0.8.1"}
    ]
  end
end

And my_app.ex contains start/2:

defmodule MyApp do
  use Application.Behaviour

  # See http://elixir-lang.org/docs/stable/Application.Behaviour.html
  # for more information on OTP Applications
  def start(_type, _args) do
    MyApp.Supervisor.start_link
  end
end

Any ideas?

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93

2 Answers2

1

You need to make sure all of your deps are in the applications list. The reason the app fails on startup is because it can't find one of your dependencies.

bitwalker
  • 9,061
  • 1
  • 35
  • 27
  • No joy... added all deps to the applications list (`applications: [:phoenix, :jazz, :cowboy, :erlcloud, :json, :amnesia]`), and I still get the same error... – Uri Agassi Jun 17 '14 at 06:17
  • Could you point me to the documentation describing the structure of `mix.exs`? – Uri Agassi Jun 17 '14 at 06:20
  • This is the best I could find, but it's not comprehensive: http://elixir-lang.org/getting_started/mix_otp/1.html – bitwalker Jun 17 '14 at 14:18
  • Is the source for this up on GitHub somewhere? I can take a look at what's going wrong here, but it's a bit difficult to troubleshoot without an example app which reproduces the problem. After re-reading through the code you posted, I see nothing wrong with what you have, so something else must be missing from the equation. – bitwalker Jun 17 '14 at 14:24
  • I've managed to get past this problem (see my answer), but I would _love_ to chat with you about the other problems I've encountered, which I believe should be tackled at the framework level (or at least raise the proper errors as soon as possible)... – Uri Agassi Jun 17 '14 at 15:20
0

The problem was solved when I figured out that another file in the project (besides my_app.ex) defined defmodule MyApp. I'm coming from ruby, and I'm used to having a module used as a package name, and be re-used as needed.

Changing the name of the second module (to MyApp.Database) got me past that problem.

The most confusing part is that the application works perfectly when run using

mix phoenix.start

I've encountered more problems after that, which are out of the scope for this question, and I might bring them up as separate questions.

Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
  • Very interesting. I would guess that the reason for that is that in development, it just redefines the `MyApp` module, but the release is running compiled code, and doesn't permit that, which is why it fails (or so I would guess). Were any of the other problems you encountered specific to exrm? – bitwalker Jun 18 '14 at 19:13
  • yes - I needed to add applications to `applications` which are not in my `mix.exs`, such as `:inflex` and `:ex_conf` - I think they should be implicitly added as applications of dependent applications – Uri Agassi Jun 18 '14 at 19:19
  • Also, I needed to add the router to the supervisor workers because I couldn't use phoenix's `mix phoenix.start` in the binary. It was exceptionally difficult, since the template where the example router worker is shown is wrong (`# worker(MyApp.Router, [])` instead of `worker(MyApp.Router, [], function: :start)` – Uri Agassi Jun 18 '14 at 19:22
  • @bitwalker - I also had other difficulties running the binary(though this is probably more phoenix related than exrm), since when you don't set the environment, by default it is run in `"dev"` mode, which fails because of code reload, and when you set it to `"prod"`, it fails because there is no `PORT` set in the environment. All of this happens with non-helpful errors, so debugging it is a bitch... – Uri Agassi Jun 18 '14 at 19:25
  • Applications which are dependencies of dependencies should be added to the dependency's mix.exs, or .app.src in the case of Erlang deps. If they aren't, then the author should be notified, as that is an issue with their application, not with the release process. – bitwalker Jun 23 '14 at 17:23
  • Interesting, the release is built with MIX_ENV=prod, so the release should contain your prod config, and the app will build with any prod specific environment settings. I'll chat with Chris McCord to see if there is anything I can do to building releases for Phoenix apps less of a pain, or at least more clear in terms of requirements. – bitwalker Jun 23 '14 at 17:25
  • @bitwalker - thanks for the attention and care, in case we choose Elixir for the coming project, I'm sure we'll talk again, and I'll be happy to contribute wherever I can. – Uri Agassi Jun 23 '14 at 18:18