Running an IEx session within an app (running as a release)?

Hello everybody,
Hope everyone is good!

TL;DR: I’m running a Phoenix app as a release where I didn’t defined anything about node configuration etc. (just ran ./prod/rel/my_app/bin/my_app start)
And I want to be able to run an IEx session in it, how can I do?

Edit: I changed the title. It was previously the following:
Best way to quickly read some ecto tables on a running application (within a release)

I am in a situation I thought it will be easy to solve but I’m finding it difficult…

I have an application running in production (deployed as a release).
It was planned to have some kind of a dashboard to see DB persisted data (and allowing to download them as CSV) but it’s not yet implemented (planned for later).
But now my customer realized it would be great if he had some data right now (before the end of the year for analysis purpose)… Something that doesn’t need to be implemented… Just one shot of the raw data (as a CSV) will be good, even if it’s grabbed manually.
So I said, sure…
Since what he really now is only in one schema (for which I already have a context function like MySchema.list_all) that don’t even had that many entries (estimated around 20 based on payments data) I thought that I’ll simply connect to an iex session and run that expression embedded in some kind of pipeline with some in order to format the output (it has some embedded schema).

Well, to begin with I’m unable to run iex because it’s a release and the container it’s running on doesn’t have iex installed…

When I run the following ps aux | grep elixir within the container, I’m getting the a result (the command) that have a --sname my_app_name and --setcookie RAnDomStriNg options… So I was thinking to connect into the node, but I’m always getting a false after a couple of seconds… I tried from my dev machine using the domain host but also from spinning up a docker container for that sole purpose on the server and connecting it to the same docker network. But I guess that won’t work anyway, because I don’t open any other port that 4000 on Phoenix. When I’m trying to do Node.connect :my_app_name I got an the error ** Cannot get connection id for node my_app_name. And when I try some kind of host combination I’m getting the error ** System NOT running to use fully qualified hostnames **

So I guess that I’m stuck not being able to run an IEx session on that running app, right?
But does anyone can confirm that or if there’s a way to still run IEx inside that release?
Also what could be done in order to make configure the release so that the next time I’ll be able to connect into it?

Now I’ll try to connect to the Postgres DB… Should be able to grab something I can make use of…

Anyway, thank you very much for any comment…

just ran ./prod/rel/my_app/bin/my_app start_iex?

1 Like

And I want to be able to run an IEx session in it, how can I do?

Hi @Sanjibukai something you can do is ssh into the machine and run rel/my_app/bin/my_app remote to connect to the running node. Does that work for you?

If you want to run iex locally in your local machine terminal to connect to the remote node, then that might be a bit more complicated, as it needs some SSH port forwarding, and passing iex options, but it’s also a possibility discussed here. This module could help you automate the port detection.


Thanks @derek-zhou for the documentation link, I don’t know why I didn’t think about that…
Thanks @rodrigues for the details.

Indeed the remote option did the trick!

Do you know that if I’m writing some code in that IEx session, like some inlined defmodule etc… Does that code be part of the running application (in memory) or does the code disappear when I’ll exit the IEx shell?

I don’t want to mess with the production environment…
I guess I’ll grab the output of the list_all and do some data mapping in my dev to be sure…

Yes it does change them, it’s safer to not redefine modules in production environment for sure.

If you really need, you can just ensure it’s a new module name to not mess with others.

1 Like