Mix release doesn't work even with server: true

I have added server: true to my code but my Mix release still doesn’t work. Did I miss anything?

My code is live on Quoc-Anh Nguyen / tools · GitLab

Please show us the full command sequence

I have a bash script to build the release build.sh · main · Quoc-Anh Nguyen / tools · GitLab.

Then I use PORT=4000 MIX_ENV=prod _build/prod/rel/tools/bin/tools start to start the server.

please share the whole sequence, ie. how you built your release.

“It doesn’t work” has no meaning to anyone other than yourself. Please explain:

  • What was your intention?
  • What did you do?
  • What did you expect?
  • what did you get instead?

Really sorry guys!

Well I’m trying to build a Mix release and try to run it. My expectation is it should work like mix phx:server.

Here is the reproducible steps:

  • Run ./build.sh to create a mix release
  • Run PORT=4000 MIX_ENV=prod _build/prod/rel/tools/bin/tools start to start the server
  • Access localhost:4000 via both browsers and curl. Both throw errors and the problem is there is no Phoenix server bind to any port.

My expectation is the server should start and bind itself to port 4000.

1 Like

and the errors are?

There is no error when I run the start command. No log, nothing. So I believe the server doesn’t start with my command.

what you mean by “no log, nothing”? Did it quit without printing anything, or hang in there not printing anything?

If you run netstat -lnt | grep 4000 do you see the listening port?

By the way, MIX_ENV=prod is unnecessary on the command line to run the release. After the release, there is no mix anymore.

I mean it just hangs in there without printing anything.

netstat -lnt | grep 4000 returns no listening port.

I am going to assume that you have DATABASE_URL and SECRET_KEY_BASE defined in the shell to run the release, otherwise, it will raise. Can you unset one of them, and see that it actually raises?

I have set them, and managed to run PORT=4000 mix phx.server' but I can see what the OP is
describing. when you run
PORT=4000 _build/prod/rel/tools/bin/tools start

the shel hangs idle

I have tweaked the configs to run exclusively on port 4000 and still does not work within the release.

these are the env var based on dev.exs

export DATABASE_URL="ecto://postgres:postgres@localhost/tools_dev"
export SECRET_KEY_BASE="mKdPiT3RyM8WSSvS1YBqkxf0ACRYPZsI8v72ewbg46T"

Currently, I use envs from .envrc.example.

If I remove DATABASE_URL, it throws an error and exits.

** (RuntimeError) environment variable DATABASE_URL is missing.
For example: ecto://USER:PASS@HOST/DATABASE

    (stdlib 3.16.1) erl_eval.erl:685: :erl_eval.do_apply/6
    (stdlib 3.16.1) erl_eval.erl:446: :erl_eval.expr/5
    (stdlib 3.16.1) erl_eval.erl:123: :erl_eval.exprs/5
    (elixir 1.13.0) src/elixir.erl:289: :elixir.recur_eval/3
    (elixir 1.13.0) src/elixir.erl:274: :elixir.eval_forms/3
    (elixir 1.13.0) lib/code.ex:404: Code.validated_eval_string/3
    (elixir 1.13.0) lib/config.ex:260: Config.__eval__!/3
    (elixir 1.13.0) lib/config/reader.ex:92: Config.Reader.read!/2

{"init terminating in do_boot",{#{'__exception__'=>true,'__struct__'=>'Elixir.RuntimeError',message=><<101,110,118,105,114,111,110,109,101,110,116,32,118,97,114,105,97,98,108,101,32,68,65,84,65,66,65,83,69,95,85,82,76,32,105,115,32,109,105,115,115,105,110,103,46,10,70,111,114,32,101,=ERROR REPORT==== 8-Dec-2021::20:35:57.227647 ===
Error in process <0.9.0> on node 'tools@Quoc-Anhs-MacBook-Pro' with exit value:
{#{'__exception__' => true,'__struct__' => 'Elixir.RuntimeError',
   message =>
       <<"environment variable DATABASE_URL is missing.\nFor example: ecto://USER:PASS@HOST/DATABASE\n">>},
             {error_info,#{module => 'Elixir.Exception'}}]},

init terminating in do_boot ({,[{erl_eval,do_apply,6,[{_},{_},{_}]},{erl_eval,expr,5,[{_},{_}]},{erl_eval,exprs,5,[{_},{_}]},{elixir,recur_eval,3,[{_},{_}]},{elixir,eval_forms,3,[{_},{_}]},{Elixir.Cod

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

If you cannot figure it out, and since it looks it is a “hello world” app I would advice you to start over and follow these guide.

I think the issue is this: Your application is called :tools which is already taken by a standard erlang application:

So the release process got confused and release that application instead. Therefore, there is nothing of your own code in the release.


There are only two hard things in Computer Science: cache invalidation and naming things.
– Phil Karlton

That’s the moral of this struggle. OTP applicaions have a flat name space, and one have to dodge the following:

Maybe the mix phx.new can be enhanced to check for potential name collisions.

1 Like

Wow, nice catch! Thank you.

Let me try with another name.