December 09, 2016

Connect to a remote Elixir node deployed with Distillery

When building Elixir apps with Distillery I don’t install Elixir on the server as Distillery bundles everything it needs.


I found that I always had to google and fiddle around a bit to connect Observer to a running app so decided to document it for myself and others.

The Code

Most existing tutorials or docs that I found assumes that epmd is accessible on the remote. This method needs nothing but standard Linux tools.

me@local:~$ ssh [email protected]
user@app1:~$ netstat -ntlap | grep LISTEN
tcp        0      0 0.0.0.0:4369            0.0.0.0:*               LISTEN      3443/epmd
tcp        0      0 0.0.0.0:39566           0.0.0.0:*               LISTEN      3439/beam.smp
tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      3548/postgres
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN      3439/beam.smp

# on local machine use ports from top two rows above to create two tunnels (3rd row is postgres and 4th is web app)
me@local:~$ ssh -L 4369:localhost:4369 -L 39566:localhost:39566 [email protected]
user@app1:~$

# on local machine in a different terminal
me@local:~$ iex --name [email protected] --cookie your-cookie # found as -setcookie in rel/<app>/var/vm.args
iex([email protected])1> Node.connect(:"[email protected]") # found as -name in rel/<app>/var/vm.args
iex([email protected])1> :observer.start

# in the Observer window that opens you can now select the remote node from the Nodes menu

Results

elixir observer

If you have a better / more concise way of connecting let me know.