Search code examples
erlangelixirelixir-mixexrm

phoenix server fails after being built with `mix release`


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?


Solution

  • 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.