What is the best way to start a long running Elixir process?

I have a Elixir application which listens for messages coming to a RabbitMQ queue. This application is a long running one which will be deployed on a remote server.

What is the best way for me to make this a long running application?

  1. Add a command line project and use mix escript.build to generate an executable. Run the executable on the server

  2. Or may be use a mix task to start the OTP application and start listening for messages

I am wondering, is there a standard way to approach this? How do you generally daemonize Elixir applications?

I’m not quite sure, if I understand you correctly, but I do assume, that you want to start your application, this gets messaged from the outside world and then does one computation per message and only shuts down on powerfailure or similar catastrophes.

If this is true, there are plenty of tools that help you to deploy for exactly this behaviour, actually, this is what BEAM is designed for!

On of these tools is exrm (source, docs). And I am not aware of others at the top of my head. Also I don’t have any experiences using it.


If I got you wrong and the concept is more like having an application out of your control which receives messages from the outside world and then starts your application in a subshell for each and every message, then your only way to go is an escript (or a bunch of *.exs, but that would mean compiling the hole program on every run).

1 Like

Yes. I wanted to start the application on a remote server and keep it running. I will take a look at exrm. Thanks