Issues trying to use FUSE on Bluemix

前端 未结 1 1493
自闭症患者
自闭症患者 2021-01-25 08:00

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

1条回答
  •  北海茫月
    2021-01-25 08:16

    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...

    1. Include into the app the private key and the known_hosts files.

    2. Push the app adding -s cflinuxfs2 parameter.

    3. 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.

    0 讨论(0)
提交回复
热议问题