7

Elixir & Mix all want to make the server as a daemon. There have not been able to find the right way.

In addition, I want to use the erlang reltool.

aposto
  • 566
  • 5
  • 14

2 Answers2

10

You can use the --detached option to start the runtime system detached from the system console. It is meant to be used for running daemons and backgrounds processes:

elixir --detached -S mix run

Regarding reltool, you can use exrm although and pass -detached (single -) when configuring the VM arguments. The full argument list for the runtime system can be found here: http://erlang.org/doc/man/erl.html

José Valim
  • 50,409
  • 12
  • 130
  • 115
  • 2
    You don't need to pass `-detached` with exrm, since running your release with `bin/myapp start` automatically runs it in detached mode. – bitwalker Jun 04 '14 at 23:46
  • but what if the host server get rebooted? Would my elixir app start automatically again? Or do I have to start it manually? – simo Aug 07 '16 at 02:36
  • @simo, you can use [supervisord](http://supervisord.org/running.html) to ensure that the process is started on reboot – sdc Sep 12 '20 at 17:34
2

You should use --erl "-detached" since Elixir 1.9+. Like this:

MIX_ENV=prod elixir --erl "-detached" -S mix run --no-halt

or for Phoenix:

MIX_ENV=prod elixir --erl "-detached" -S mix phx.server
Mikhail Chuprynski
  • 2,404
  • 2
  • 29
  • 42