Running elixir application as server (always running)

I have a simple application that I’ve coded as an escript, but would like to convert it to a server that periodically runs the code (every hour).

When running the application it always exits.

I’ve changed it to use OTP coding principles with a single supervisor and genserver, but I can’t manage to get the application to start and stay running. Things I’ve tried…

mix app.start --permanent
elixir -pa <path_to_ebin_app> --app cel_server

I also incorrectly tried kicking off an infinite loop structure from the GenServer init function and many other poor attempts to get it working.

What is the best way to start an application that you want to run like a server.


If it really is to run a command every hour, use cron instead. It gives you so much more out of the box like logging, emails on failure, it is already running at boot and ugh you don’t need to start it everytime.


Regardless of the use case, how would one start of a long running elixir application? I happen to be looking for something similar, although my use case is to start a worker process that process a queue.

Most forum threads I found suggested going for something like a exrm, which I find to be an overkill and adds too much complexity when I’m hoping a simple mix task would suffice.


I’m not sure if it is idiomatic but after starting the supervisor I usually
request a monitor and then I go into a receive loop that discards all
messages except for the DOWN message of the supervisor and leaves the loop
on receive. There are also other signals imaginable.

1 Like

Thanks for the info.

I agree cron would do the trick, if that’s all I had planned. However I’m going to be running it in a docker container and don’t want any external dependencies.

I also have it set up as an umbrella application with additional apps that have not yet been coded, some of which will also need to be running indefinitely, processing queues.

I also looked into the possibility of setting up quantum-elixir, but that also exited before doing anything.

1 Like

If you deploy into docker, you should do proper OTP releases using destillery or what it was called as well. Such releases do fit very well into a docker scenario.


Thanks, for the tip. Still learning and distillery was something I hadn’t dug into yet.

1 Like