Connecting Juno to work with Julia installed on a remote server

Hello,
I am trying to work with Juno using Julia installed on a powerful server, for which I have SSH (and a not-default port let’s call it #SPORT).
I am trying to follow the documentation at http://docs.junolab.org/latest/man/faq.html but I am lost at:

Linux/Unix: Open a local terminal and connect to your remote server : ssh -R PORT#1:localhost:PORT#2 your.server.com

The previous command (Julia Client: Connect External Process) reported me using Juno; Juno.connect(32995), so 32995 is PORT#2, but what is it PORT#1 ?

Where do I put username and password for the server ? And then, after I did connect on the server ?

You can pick PORT#1 yourself and you have to use it when starting Julia on the server, i.e.: you should run using Juno; Juno.connect(PORT#1) there.

When you run the SSH command to set up a port forward it should ask for the password. You can always go with passwordless key-based authentication for SSH to get rid of the password prompt.


It took me a sec to figure this out, so perhaps this could be useful for people:

The semantics of the -R flag when calling SSH like ssh -R <server>:<host>:<client> <hostname> are that the connections to port <server> on the server <hostname> get forwarded on the client machine to <host>:<client>.

<host> in this case should be the client machine itself (i.e. localhost) and the port <client> is the one given by Juno/Atom (the Juno plugin for Atom listens for incoming connections on the local machine on that port). On the server the Julia session should connect to the local port <server>, which then gets forwarded from the server to the client .

Sorry, still I don’t get it (I know little of networks).

So, my server (mydomain.org) has Julia installed and available to users, sshd open at port 5100 and I did open an other port on the firewall (iptables) at 5130. My username is mrwhite

Now, from Juno on my desktop I selected Julia Client: Connect External Process and got as response to run using Juno; Juno.connect(33125).

I then typed on a terminal:
ssh -R 54130:localhost:33125 mrwhite@mydomain.org -p 54100

That logged me to the server on mydomain.org

Do I need to do anything on Juno now (in particular do I need to type using Juno; Juno.connect(33125) ) ? Do I need to run Julia on the server ?

If I type a=3+3 I run what it looks the local version of Julia, while if I type using Juno; Juno.connect(33125) I get:

ERROR (unhandled task failure): ArgumentError: stream is closed or unusable
Stacktrace:
 [1] check_open(::TCPSocket) at ./stream.jl:251
 [2] uv_write(::TCPSocket, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:795
 [3] unsafe_write(::TCPSocket, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:832
 [4] print(::TCPSocket, ::String) at ./strings/io.jl:122
 [5] print(::TCPSocket, ::String, ::Char, ::Vararg{Char,N} where N) at ./strings/io.jl:40
 [6] println(::TCPSocket, ::String, ::Vararg{String,N} where N) at ./strings/io.jl:54
 [7] msg(::String, ::Dict{Symbol,Any}, ::Vararg{Dict{Symbol,Any},N} where N) at /home/lobianco/.julia/v0.6/Atom/src/comm.jl:124
 [8] macro expansion at /home/lobianco/.julia/v0.6/Atom/src/comm.jl:64 [inlined]
 [9] (::Atom.##11#13)() at ./event.jl:73

EDIT: Somehow I finally got the “Julia is connected” message… but then if I remove the connection it still seems to work… how can I check if I am using a local julia version or the remote one? (also, I got the message only once, I am unable to reproduce it again :-/)

AFAICT you should rather use ssh -R 54100:localhost:33125 mrwhite@mydomain.org, then start Julia in the remote shell and call using Juno; Juno.connect(54100).

1 Like

Got it :slight_smile:

Laptop, Juno: CTRL+ALT+P → Julia Client: Connect External Process and take note of the #junoport
Laptop, terminal: ssh -R 54130:localhost:#junoport mrwhite@mydomain.org -p 54100
Server: julia
Server: julia> using Juno; Juno.connect(54130)

On the Laptop you should now get the message “Julia client. Client connected.”
The only problem is that while numerical results are displaied in Juno, println() are made on the terminal on the server. Is it possible to forward also those to Juno on the laptop ?

2 Likes

Does this still work on the latest releases? I’ve been trying to get it to work, it seems that the two processes (local Juno, serverside julia) do seem to be able to connect and talk to eachother, however in the server side julia process I receive the message:
WARNING: Atom.jl: unrecognised message connected.,
and when I try to start the julia repl, it just hangs on Starting julia....

I’ve updated Atom.jl and Juno.jl, checked both out etc, doesn’t change anything. Tried it purely locally, same error message. Any ideas?

The warning is harmless, afaict.

This does still work, but the new Juno REPL does not work when connecting to an external process unfortunately. I’ll see what I can do about that though.

1 Like

Ah, I see, probably that’s why it seems like it’s trying to connect but no actual data flows.

So far I’ve only tried this locally, but connectng to an external process does work if you eval from an editor.

You’re absolutely right! Works using servers too!

1 Like

Does anyone know if the client port can be made static? Right now I have to change ports each time atom boots

1 Like

Tried to do this with a google cloud platform VM instance.

After obtaining the port number from Atom (e.g. 32785) , started up an ssh session to remote instance like this:

gcloud compute ssh --project "test-project1"  --zone "us-east1-b"  --ssh-flag="-R 32785:localhost:80"  test1

Then started Julia from the remote console and got this:

using Juno; Juno.connect(32785)
connect_to localhost port 80: failed.

Any ideas how to resolve?

I cannot answer on your specific question but here’s what I do to make the changing port number less burdensome.

On the local machine I created the following script to connect to the remote server

sshServername.sh

#!/bin/bash
#title           : sshServername
#description     : Connect to remote server with port forward
#date            : 12-12-2016
#version         : 0.0.1
#==============================================================================

ssh -X -R 40000:localhost:$1 doris.ouranos.ca

Add sshServername.sh to PATH and chmod +x sshServername.sh

On the remote server, I put the following lines in .juliarc.jl

using Juno
include("/home/user/Julia/JunoUtils.jl")
try
  junoC()
catch
  #do nothing
end

Where in JunoUtils.jl there is the following code

function junoC()
  Juno.connect(40000)
end

So the workflow is the following.
1- get the client local port number PORT in Juno
2- connect to remote server with sshServername PORT
3- start julia on the remote server

I guess there could be a quicker way to connect but it’s enough for me.

Port 80 is usually used by the browser. Tried with another port?

edit - I think the flag should be

--ssh-flag="-R 80:localhost:32785"

?

Thanks @Balinus, yes I had it around the wrong way. Works. Yes, and need to choose a port that isn’t in use by anything else.

Ok thanks–this works but not ideal. With Jupyter and Hydrogen (atom), I use the same port each time so I can use the same persistent SSH connection. Hopefully port can be added to Juno settings, or just make it deterministic.

1 Like

Yes, a static port would be ideal. I’m sure it’s possible, I just don’t know where to look though!

I think there’s an issue for that somewhere – should be fairly trivial to implement IIRC.

I just submitted a pull request with this feature: https://github.com/JunoLab/atom-julia-client/pull/479

1 Like

How are you able to interact with the remote REPL once its connected in Juno? I ran a code block from my local machine but there is no response locally or on the server