I have a java app.
I need to start a script from this app.
If I execute the command to start the script directly in terminal, I get the desired result, like:
root@host [ ~ ]# docker exec -it mycontainer bash
root [ /mycontainer ]# nsenter -t 1 -m -u -n -i sh /gg/my.sh -c telegraf -a status
status #some custom output from the script
telegraf
**************
207
If I start exactly the same thing from the Java app I don't get the correct result. (The result is as if I execute the script inside the container.) Java code:
String command = "nsenter -t 1 -m -u -n -i sh /gg/my.sh -a " + action + " -c " + name;
Process ps = Runtime.getRuntime().exec(command);
...
log.info(psOutput)
Log:
not found
**************
not implemented.
Full context:
- the Java app is in docker container
- I need to run the script on the host
yes, I know.. process isolation and docker containers and etc, sometimes you just have to trigger the execution of a set of commands on the host from the container. I trigger the execution of the script from the container onto the host following this.
Can someone explain to me why? What exactly happens when I execute my command from the Java app? Why does it feel like the process which is started from the Java app is sort of wrapped in another process, maybe?