5
votes

I am trying to create a release of a stock Phoenix application (based on Elixir and Erlang) using exrm.

The first release for the dev mix environment is created fine, but crashes when run using ./rel/my_app/bin/my_app console. This happens running Ubuntu 14.04 inside a Vagrant/Virtual Box virtual machine.

On my Mac, the same setup runs fine. Unfortunately, I need to build the release on a machine with the same architecture as the target server, which will run Ubuntu.

You can find the application here: https://github.com/mavenastic/my_app. It includes the steps taken to install dependencies and create the project on the VM (see STEPS.md) as well as a Erlang crash dump.

Here is the error I get from attempting to run the console:

{"Kernel pid terminated",application_controller,"{application_start_failure,my_app,{{shutdown,{failed_to_start_child,'Elixir.MyApp.Endpoint',{shutdown,{failed_to_start_child,'Elixir.Phoenix.CodeReloader.Server',{undef,[{'Elixir.Mix.Project',config,[],[]},{'Elixir.Phoenix.CodeReloader.Server',init,1,[{file,\"lib/phoenix/code_reloader/server.ex\"},{line,29}]},{gen_server,init_it,6,[{file,\"gen_server.erl\"},{line,328}]},{proc_lib,init_p_do_apply,3,[{file,\"proc_lib.erl\"},{line,240}]}]}}}}},{'Elixir.MyApp',start,[normal,[]]}}}"}

EDIT:

I tried to create a release for the production environment as well with MIX_ENV=prod mix release. The release is successfully generated and MIX_ENV=prod PORT=8889 ./rel/my_app/bin/my_app console runs fine. However, I cannot ping the server nor run a remote console once it starts, so it seems something is still missing for the application to run properly.

$ MIX_ENV=prod PORT=8889 ./rel/my_app/bin/my_app start
$ MIX_ENV=prod PORT=8889 ./rel/my_app/bin/my_app ping

=INFO REPORT==== 24-Oct-2015::10:28:25 ===
Protocol: "inet_tcp": register/listen error: econnrefused
escript: exception error: no match of right hand side value
                 {error,
                     {{shutdown,
                          {failed_to_start_child,net_kernel,
                              {'EXIT',nodistribution}}},
                      {child,undefined,net_sup_dynamic,
                          {erl_distribution,start_link,
                              [['[email protected]',longnames]]},
                          permanent,1000,supervisor,
                          [erl_distribution]}}}

$ ps aux | grep my_app
vagrant   2572  0.0  0.0   7532    96 ?        S    10:28   0:00 /vagrant/my_app/rel/my_app/erts-7.1/bin/epmd -daemon
vagrant   2575  0.0  0.2   9448  2256 pts/0    S+   10:28   0:00 grep --color=auto my_app

$ MIX_ENV=prod PORT=8889 ./rel/my_app/bin/my_app remote_console
$

Also, from what I gathered, I should be able to create a release for the dev or any other environment as well. So the missing piece might affect both environments.

Thanks in advance!

4

4 Answers

2
votes

To me it looks like the problem is that you're creating the release in your dev environment (instead of the prod env).

This part:

{undef,[{'Elixir.Mix.Project',config,[],[]}

of the (terribly and awesomely à la Erlang) error message basically says that Mix.Project.config/0 is undefined. Mix is not included in releases but I'm guessing Phoenix uses it in its code reloader, which you usually don't run in production.

Try generating the release with MIX_ENV=prod and see if it works.

1
votes

I put this in the issue tracker, but just for posterity here as well:

You need to add server: true to your prod.exs under the config for MyApp.Endpoint. This is how Phoenix starts itself within a release.

With Phoenix, I would recommend always using MIX_ENV=prod for releases, MIX_ENV=dev has a lot of development specific features (such as code reloading), that either won't work within a release, or won't work as expected.

If you are getting config errors, it's probably because you are missing some required Phoenix configuration in your environment-specific file. You can test this by running MIX_ENV=prod mix compile to see if it compiles successfully. You can also build your release with --verbosity=verbose to get detailed output for tracing down problems.

The reason why you couldn't ping or console to the release is because it failed on startup.

1
votes

@bitwalker is correct, in your config/prod.exs file you must add server: true a la http://www.phoenixframework.org/v0.13.1/docs/advanced-deployment.

I cloned your project and generated a dev release and am getting the same failure you are. I have gotten this same failure on many of my personal projects with the dev build. However, the prod build always still works.

Thus, after putting in place a config/prod.secret.exs with the correct information in it and adding the server: true to my config/prod.exs file, I am able to generate a prod release and execute console, start and ping successfully. I suspect the hot code reloader could be the culprit in the dev build but have no proof excluding it being present in the error and definitely something that is different about dev vs prod.

BTW, when starting the application, you only need to specify the PORT, not MIX_ENV as this is a release and mix is not in play:

PORT=4000 bin/my_app start

My advice is to skip the dev build and just use a staging and prod build. If you do not have a staging server, you can deploy the staging release to a local machine a la https://exrm.readme.io/docs/deployment.

0
votes

Per @bitwalker suggestion, using the master branch of exrm fixed the issue.