How do Elixir with Mix make a daemon?
Asked Answered
O

2

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.

Ozonize answered 4/6, 2014 at 13:48 Comment(0)
P
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

Prow answered 4/6, 2014 at 14:40 Comment(3)
You don't need to pass -detached with exrm, since running your release with bin/myapp start automatically runs it in detached mode.Fishwife
but what if the host server get rebooted? Would my elixir app start automatically again? Or do I have to start it manually?Brassard
@simo, you can use supervisord to ensure that the process is started on rebootWilkison
A
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
Auspex answered 29/11, 2020 at 6:27 Comment(1)
where do logs go using these commands?Intervocalic

© 2022 - 2024 — McMap. All rights reserved.