I launch a jar
from the console and it runs fine:
nohup /usr/bin/java -jar payara-micro-5.183.jar myapp.war > log.out 2>&1 & echo $!
When I run the same command from a distant computer with sshj
, it returns a pid but the process can't be seen in the console, and actually the process doesn't run. In both cases I log via ssh, public key, with the same user.
The code running the command via sshj
:
try (Session session = sshClient.startSession()) {
final Command cmd = session.exec("nohup /usr/bin/java -jar payara-micro-5.183.jar myapp.war > log.out 2>&1 & echo $!");
String response = (IOUtils.readFully(cmd.getInputStream()).toString());
// response shows a pid number
cmd.join(2, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
//exit status is 0
}
Solution:
With a previous command, I had cd
to the directory where the jar is situated.
but this cp
doesn't remove the need to use full paths for files used in the commands run after