Process dies after Jsch exits
I have a shell script that starts tomcat using 'catalina.sh start'. This script runs fine and starts tomcat which stays up even if I exit from my ssh session.
I am trying to invoke this script from Jsch
shell = new JSch();
session = shell.getSession(user, host, SSH_DEFAULT_PORT);
session.setConfig(config);
session.setPassword(password);
session.connect();
commandChannel = (ChannelExec) session.openChannel("exec");
commandCh开发者_C百科annel.setCommand(command);
commandChannel.setPty(true);
commandChannel.connect();
This calls my script fine and tomcat starts up, but as soon as the process exits, tomcat is given a shutdown signal and it shuts down. I tried to use setDaemonThread without success. Any idea why this is happening?
UPDATE: The script also does a couple of sudo operations unrelated to starting tomcat so it needs tty. The user is setup in sudoers so as not to require a password, so no prompt is needed.
I believe that you shouldn't allocate a pty to the command for the command to run in the background and not be attached to a terminal. What happens if you do commandChannel.setPty(false)
instead?
EDIT: are you actually running sudo and supplying a password in the script? Shouldn't you run it as root instead?
If using sudo is what you want, after running the commands detach them from the terminal using disown
or nohup
(explanation)
Does this problem happen only when your session exits immediately? It sounds like the command you run spawns a separate process. Perhaps you are not giving enough time for the other process to be spawned.
What happens if you execute your command with nohup?
精彩评论