Run SSH Task Using sudo In Background

I am using ANT sshexec to deploy and start my application, however, I can't get it to work efficiently with TeamCity 9.

My ant target looks something like this:

 <target name="start">
<sshexec host="${}" username="${linux.username}" keyfile="${linux.password}"
command="sudo -u myuser /home/myuser/bin/ ${env}"
trust="true" timeout="900000" failonerror="false"/>

Note the 15 minute timeout and failonerror = false.

This is because ant or TeamCity don't notice when the script has completed and they wait for sshexec to time out. Time out is normally an error so we have to set it to false to have a successful build.

The script launches several long long running java processes that are supposed to run in the background.

If I add usepty=true TeamCity notices when the script has finished, and ends in a timely manner, however, it closes the terminal and all the child processes including background processes.

I have tried adding nohup and & inside the script and also tried in the call to the script but TeamCity still closes them.

Is there a trick to running scripts like this that doesn't rely on a long timeout?

Please sign in to leave a comment.