EDIT: I believe the issue is that the ssh connection is creating background connections that are still open (cf. https://superuser.com/a/617670). I would run ssh with the
-f flag, but I need to be sure that java is installed. Is there an easy way to force the connection to close from the script itself?
N.B., the remote machine is on Ubuntu 14.04.
I'm using a tool written in Clojure that calls Java's
Runtime.getRuntime().exec() like so:
Runtime.getRuntime().exec("ssh", "-o", "StrictHostKeyChecking=no", "user@host", "sudo su -");`
And then with the java.lang.Process created from that, I get the stdin and write the contents of a file to it, basically,
.close the writer. Everything works fine; there are many of these, all happening without any problems, but I have one near the beginning that runs a script that looks like this:
if [ ! $(which java) ]; then apt-get update -q apt-get install -y openjdk-7-jre fi
And when I manually ssh into the node, I see that Java gets installed successfully and the process exits. But for some reason this is not being communicated to the calling code (i.e., the java Process from above).
I mentioned before that there are many of these, and none of them hang. I have scripts that do all kinds of stuff, but also others that do almost the same thing as the above, the only difference being that they install different software (like git), and they don't hang.
So I tried doing this manually; i.e., going to a shell and typing:
ssh -o StrictHostKeyChecking=no -o ubuntu@somehost sudo su -
and then pasting the script there, and everything works great.
Not sure what could be causing this.