Attach an iex session to the elixir / OTP process

I have an elixir / OTP application launched during the creation process that started with mix phoenix.server . It has several processes that hold state. One of them is a wallet, implemented as an agent, which currently has a state that I would like to change manually, without stopping the entire application. As soon as I am in the iex session inside the application, it will be trivial, but I do not know if such an option is possible in the elixir?

+5
source share
1 answer

It depends on how you started the OTP application. To connect to a node, it must be started using the --name or --sname . You can check the name of the current session with node()

 $ iex Erlang/OTP 18 [erts-7.2.1] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false] Interactive Elixir (1.3.0) - press Ctrl+C to exit (type h() ENTER for help) iex(1)> node() : nonode@nohost 

The name node is an atom, where the first part is the actual name of the node and the second is the host. The host is used for routing, so it’s hard to connect to a node that is deployed to nohost .

If you run iex with a short name ( --sname ), it will automatically determine your hostname.

 $ iex --sname foo --cookie ciastko (...) iex( foo@MacBook-Pro-Tomasz )1> node :" foo@MacBook-Pro-Tomasz " 

In another console, launch iex with a different name and the same cookie and try Node.connect(:" foo@MacBook-Pro-Tomasz ") . They must connect.

You probably haven't run the phoenix app with this, and now you cannot connect. To start Phoenix with this feature next time, you need to run:

 elixir --sname some_name --cookie ciastko -S mix phoenix.server 
+11
source

All Articles