So, I have the following problem: I have a web service running inside the Tomcat7 server on Linux. However, the web service must execute some commands (mainly file operations such as copying and mounting). Copy I replaced java.nio, but I don't think there is a replacement for mount.
So, I am trying to execute shell commands from my Tomcat Java process. Unfortunately, he does not execute my commands . I have already implemented shell command execution in Java. Therefore, my code should be correct:
Process pr = Runtime.getRuntime().exec("mount -o loop -t iso9660 <myimage> <mymountpoint>");
pr.waitFor();
<myimage>and <mymountpoint>are absolute paths, so no problem.
- I debugged my commands and they work when executed on the console.
- I tried sending other commands. Simple commands like
idand pwdwork! - I tried using
/bin/bash -c "<command>"one that didn't work. - I tried to execute a shell script that executes a command that does not work.
- I tried to avoid gaps in my team, which did not work.
So, I went even deeper, and now I suspect some Tomcat security policies ( Sandbox ?), Which prevents me from executing the command. Since security is not a problem for me (this is an internal system completely isolated from the outside world), I tried to hack, which recently became popular:
System.setSecurityManager(null);
. Java7 Tomcat7 RHEL6. Tomcat7 ! /etc/.. , /opt/tomcat/, zip Tomcat. /opt/tomcat/conf , , , catalina.policy, , .
?