Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Run Phoenix in Production Forever

I'm trying to run my Phoenix app in production forever, i.e., independently of my terminal process. I saw in Phoenix guides and in a Stackoverflow question that I can use elixir --detached, but I'm not being able of using those commands properly. In fact I was able, once, of starting it like that but I tried so many commands that I don'e even know which one make it (also because there's no message to make it clear). So, using the latest version of Phoenix (1.1) and Elixir (1.1.1), what are the commands to: 1) start the server forever (as a daemon); 2) stop the server without the need of rebooting the server?

like image 787
Paulo Janeiro Avatar asked Dec 23 '15 22:12

Paulo Janeiro


2 Answers

I never figured out how to run an Elixir/Phoenix app as a daemon using the --detached switch myself. However, I can tell you that building an OTP release with Exrm is the way to go. It may seem a little intimidating at first, but I promise it is rather easy and after a couple of builds will be virtually mindless for you. Additionally, if you will invest the time to learn Exrm now, you will not have to refine your production deployments later.

There is a Phoenix Guide for Exrm Releases. Additionally, I just released an ExCasts epsiode on the subject. While this episode does not specifically cover a Phoenix release with Exrm, all of the concepts and demonstrations are applicable. Using Exrm to build OTP releases has many benefits that are covered in the episode, including a script generated with several commands, including but not limited to: console, remote_console and hot upgrade/downgrade. This means you can deploy your application without restarting the application.

Hope this helps and good luck!

like image 186
Jason Harrelson Avatar answered Sep 22 '22 01:09

Jason Harrelson


Also, see the excellent distillery library. The GitHub is here: https://github.com/bitwalker/distillery

There is also a guide for getting your phoenix application up and running:

https://hexdocs.pm/distillery/phoenix-walkthrough.html#phoenix-walkthrough

Afterwards, you can run the process in the foreground or in the background regarding your preference.

like image 22
Tim de Jager Avatar answered Sep 21 '22 01:09

Tim de Jager