We have an elixir app running in prod. I can SSH onto this box, but is it possible to connect to the app with an iex session? When I run ./bin/foobar start_iex I get an error:
Protocol 'inet_tcp': the name foobar@ip-1-2-3-4.ec2.internal seems to be in use by another Erlang node
I know something about --cookie and --sname to connect to a session, but I do not know how the prod app was started. Is it possible to know the cookie or session from bash command line? And is better to SSH onto box or to connect to remote iex session directly from my local computer?
Hi @dodo! and welcome to the community.
One way you could achieve that is:
Modify systemd service so it starts the application with the name (e.g. prod): elixir --sname prod -S mix phx.server
Now we can connect to it from the same machine with: iex --remsh prod --sname dev
I’ve never run this way in production, though… not sure if this is idiomatic =)
In case it is useful to anyone, at the conclusion of your Elixir build you will likely see something like:
Release created at _build/prod/rel/app_name
# To start your system
_build/prod/rel/app_name/bin/app_name start
Once the release is running:
# To connect to it remotely
_build/prod/rel/app_name/bin/app_name remote
After SSHing to your web server, if you run _build/prod/rel/app_name/bin/app_name remote you will have an iex session connected to your running application.
If you are using Phoenix, you can confirm this is the case by running Phoenix.Endpoint.server?(:app_name, BrandhubWeb.Endpoint) which will now return true (whereas a straightup iex -S mix session will not).