问题
I was looking for a way to add a remote file system accessible into Bluemix. In this post I was told to use cflinuxfs2 stack which is supported in last versions of Cloud Foundry.
I was able to execute mkdir command for the mount point from my Java app and execute sshfs command but this last one fails with: "read: Connection reset by peer".
The point is that the same commands used in a Linux box at home work fine so I understand the command, the ssh key and the know hosts files are ok.
This is the piece of Java EE code deployed into Liberty runtime in Bluemix:
String s = null;
Process p = null;
BufferedReader br = null;
try
{
p = Runtime.getRuntime().exec("mkdir -p /home/vcap/misc");
br = new BufferedReader(new InputStreamReader(p.getInputStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command mkdir with exit: " + p.exitValue());
p.destroy();
br.close();
p = Runtime.getRuntime().exec("sshfs ibmcloud@129.41.133.34:/ /home/vcap/misc -o IdentityFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key -o StrictHostKeyChecking=yes -o UserKnownHostsFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts -o idmap=user -o compression=no -o sshfs_debug");
br = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while((s = br.readLine()) != null)
System.out.println("line: " + s);
p.waitFor();
System.out.println ("#### Executing command sshfs with exit: " + p.exitValue());
p.destroy();
br.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
catch(InterruptedException ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(br != null)
br.close();
}
catch(IOException ex)
{
ex.printStackTrace();
}
}
Referenced files in the commands are included in the EAR file and pushed as part of the app. I can see them and their content browsing the file system from Bluemix dashboard.
Browsing the web, I found tons of post about error message: "read: Connection reset by peer" but it seems they don't apply to my case or they are related to firewalls and config files I have no access in Bluemix. And as I said, the same two commands executed in my linux box at home work fine.
Any idea or recommendation to get it working? Anybody tested this idea before in Bluemix?
Thanks!
回答1:
Ok, finally I found the reason of the issue with the help of team colleagues. Problem was with permissions of the private ssh key. It has to be 600 and by default it was 644 after the cf push
.
So here it is the final code (quick and dirty) that worked, just in case it can be useful to others...
Include into the app the private key and the known_hosts files.
Push the app adding
-s cflinuxfs2
parameter.Execute at runtime startup some code like this:
String s = null; Process p = null; BufferedReader br = null; try { p = Runtime.getRuntime().exec("mkdir -p /home/vcap/misc"); br = new BufferedReader(new InputStreamReader(p.getInputStream())); while((s = br.readLine()) != null) System.out.println("line: " + s); p.waitFor(); System.out.println ("#### Executing command mkdir with exit: " + p.exitValue()); p.destroy(); br.close(); p = Runtime.getRuntime().exec("chmod 600 /home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key"); br = new BufferedReader(new InputStreamReader(p.getInputStream())); while((s = br.readLine()) != null) System.out.println("line: " + s); p.waitFor(); System.out.println ("#### Executing command chmod with exit: " + p.exitValue()); p.destroy(); br.close(); p = Runtime.getRuntime().exec("chmod 600 /home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts"); br = new BufferedReader(new InputStreamReader(p.getInputStream())); while((s = br.readLine()) != null) System.out.println("line: " + s); p.waitFor(); System.out.println ("#### Executing command chmod with exit: " + p.exitValue()); p.destroy(); br.close(); p = Runtime.getRuntime().exec("sshfs ibmcloud@129.41.133.34:/home/ibmcloud /home/vcap/misc -o IdentityFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/cloud.key -o StrictHostKeyChecking=yes -o UserKnownHostsFile=/home/vcap/app/wlp/usr/servers/defaultServer/apps/myapp.ear/known_hosts -o idmap=user -o compression=no -o sshfs_debug"); br = new BufferedReader(new InputStreamReader(p.getInputStream())); while((s = br.readLine()) != null) System.out.println("line: " + s); p.waitFor(); System.out.println ("#### Executing command sshfs with exit: " + p.exitValue()); p.destroy(); br.close(); p = Runtime.getRuntime().exec("ls -l /home/vcap/misc"); br = new BufferedReader(new InputStreamReader(p.getInputStream())); while((s = br.readLine()) != null) System.out.println("line: " + s); p.waitFor(); System.out.println ("#### Executing command ls with exit: " + p.exitValue()); p.destroy(); br.close(); } catch(IOException ex) { ex.printStackTrace(); } catch(InterruptedException ex) { ex.printStackTrace(); } finally { try { if(br != null) br.close(); } catch(IOException ex) { ex.printStackTrace(); } }
This snippet should create a folder, mount a remote file system into that folder and list the content of the remote file system.
来源:https://stackoverflow.com/questions/30470112/issues-trying-to-use-fuse-on-bluemix