Running Phoenix application as a daemon?

1,345 views
Skip to first unread message

David Chin

unread,
Sep 6, 2014, 12:09:03 PM9/6/14
to elixir-l...@googlegroups.com
Hi all,

In the documentation at https://github.com/phoenixframework/phoenix, we're told to run 'mix phoenix.start' in order to start our app.

(1) Is there a way to have our app run in the background, as a demonised process, and have control of the shell returned to us once the app is started?

(2) Can we then run a command like 'mix phoenix.stop' that will gracefully shut down the running Elixir app process?

Note that when executing a Cowboy app from the command line (see the Getting Started guide at http://ninenines.eu/docs/en/cowboy/1.0/guide/getting_started/) without any options, say, '$ ./_rel/hello_release/bin/hello_release', we get to choose from the following options presented on-screen:
-> Usage: hello_release {start|start_boot <file>|foreground|stop|restart|reboot|ping|console|console_clean|console_boot <file>|attach|remote_console|upgrade}

Thanks!

Saša Jurić

unread,
Sep 6, 2014, 12:20:51 PM9/6/14
to elixir-l...@googlegroups.com
You need to build an OTP release using exrm (https://github.com/bitwalker/exrm), and then you'll have the similar interface as the Cowboy app (which is also built as an OTP release).

Some more detailed guides related to Phoenix can be found here: https://github.com/lancehalvorsen/phoenix-guides
I don't know how complete + up-to-date these guides are. In any case, you may want to take a look at the deployment tutorial (https://github.com/lancehalvorsen/phoenix-guides/blob/master/deployment.md) where exrm is used to build a relase, which is then started as a daemon.

Shane Logsdon

unread,
Sep 7, 2014, 11:39:03 AM9/7/14
to elixir-l...@googlegroups.com
I recently wrote the deployment guide to which Saša is referring, so it should be up to date. Let me know if you have any issues with the guide.

Lance Halvorsen

unread,
Sep 7, 2014, 7:36:54 PM9/7/14
to elixir-l...@googlegroups.com
A note about the guides in general: they are in a very early stage, more like rough drafts, really. We made the decision to open them up because they can be of value just as they are, and interest in Phoenix is really quite strong. We are working hard to make them better and more complete, so check back from time to time if the information you're looking for isn't there yet.
Thanks!
.L
--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric B

unread,
Sep 8, 2014, 5:18:07 AM9/8/14
to elixir-l...@googlegroups.com
I'm totally noob and I followed your guide (https://github.com/lancehalvorsen/phoenix-guides). but I couldn't access my phoenix app.

I used: 
elixir --version: Elixir 1.0.0-rc1
phoenix: v0.4.0
exrm: 0.14.2

checked phoenix app work

$ mix phoenix.start
$ curl http://localhost:4000 => got http response

then release app

$ mix release
==> The release for my_app-0.0.1 is ready!
$  cd rel/my_app/
$ ./bin/my_app start
$ ./bin/my_app ping
pong
curl: (7) Failed to connect to localhost port 4000: Connection refused

also tried
$ MIX_ENV=prod PORT=4000 ./bin/my_app start
curl: (7) Failed to connect to localhost port 4000: Connection refused

Any advice will be appreciated.

Xiaobin Xu

unread,
Sep 8, 2014, 6:30:05 AM9/8/14
to elixir-l...@googlegroups.com
  I tried exrm like a month ago and also failed to build runnable release, it seems like something wrong with supervisor tree thing.
  Till now I'm busy on my project's feature development, so I don't have many time to do deployment tests, I just made a startup shell with nodetool escript and --detached option of elixir:
   a. to start phoenix in background:
     MIX_ENV=$ENV elixir --detached --no-halt --name "$NAME" --cookie "$COOKIE" -S mix phoenix.start
   b. to stop phoenix process:
      escript nodetool -name "$NAME" -setcookie "$COOKIE" stop
   c. to test is phoenix alive:
       escript nodetool -name "$NAME" -setcookie "$COOKIE" ping

   It's definitely not the best practise but works for now, may it helps.

Shane Logsdon

unread,
Sep 8, 2014, 9:15:02 AM9/8/14
to elixir-l...@googlegroups.com
Eric,

From the sounds of it, your router isn't being started when your application is started. This occurs with `mix phoenix.start`, but exrm releases only start your application when started. To overcome this, be sure to add your router as a worker to your application's supervisor. Take a look at the end of the Setup subsection (https://github.com/lancehalvorsen/phoenix-guides/blob/master/deployment.md#setup) for how to do this. (tl;dr you need `worker(MyApp.Router, [], function: :start)` in your supervisor tree. Be sure to read the note about `mix phoenix.start` that follows that subsection.

Xiaobin, These steps may help you as well, so you might want to give them a try.

Let me know if you're still experiencing issues with this, and I'll see what I can do.

Eric B

unread,
Sep 8, 2014, 11:29:35 AM9/8/14
to elixir-l...@googlegroups.com
Thank you guys, I finally did it!

David Chin

unread,
Sep 8, 2014, 12:53:04 PM9/8/14
to elixir-l...@googlegroups.com
Thanks so much everyone - it worked for me too!

Drew Olson

unread,
Sep 8, 2014, 3:56:15 PM9/8/14
to elixir-l...@googlegroups.com
While it probably isn't as elegant as using releases, I'm running my Phoenix application as a daemon by installing elixir on the application box and using god[1]. I'm assuming any sort of process monitor would do the trick.

- Drew


On Mon, Sep 8, 2014 at 11:53 AM, David Chin <dlc...@gmail.com> wrote:
Thanks so much everyone - it worked for me too!

--

José Valim

unread,
Sep 8, 2014, 5:16:39 PM9/8/14
to elixir-l...@googlegroups.com
elixir also supports the --detached option. If you give the Elixir node a name, you can connect to it with iex --remsh.



José Valim
Skype: jv.ptec
Founder and Lead Developer

Saša Jurić

unread,
Sep 9, 2014, 1:33:19 AM9/9/14
to elixir-l...@googlegroups.com
And it’s worth mentioning that there is a “heart” Erlang option available which may remove the need for god:


You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-talk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-talk/6jlX_ARF0yw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-ta...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages