SSH Timeout problem with Jenkins and maven ant plugin

The problem:

Recently a Jenkins job would report a problem from a particular script:

Remote command failed with exit status -1.

This problem happened when using the command sshexec task from maven ant plugin:

<sshexec host="${host}" username="${login}" password="${pwd}" command="sh longcommand.sh" trust="true"

After long investigation I realised the problem was not coming from the script but from the distant server. Indeed the connection with the server would stop when a process was running more than 200 seconds.

The solution

    Ssh Configuration solution

At first I decided to modify directly the ssh configuration of the distant server.

http://z9.io/2008/12/10/how-to-fix-ssh-timeout-problems/

I modified directly in the file  /etc/ssh/sshd_config the value ClientAliveInterval from 200 to 2000. Then I restarted the server httpd : /etc/init.d/sshd restart . It fixes the issue but the solution was refused.
Therefore I decided to modify the ssh client configuration instead. But I did not find how to configure the sshexec task https://ant.apache.org/manual/Tasks/sshexec.html. I don’t have access to /etc/ssh/ssh_config in the client machine either.

Workaround for running long command remotely.

This solution works for me :https://groups.google.com/forum/#!msg/rundeck-discuss/iK55if9Vk9E/skNPHAfF3qgJ.

Instead of running:


sh longcommand.sh

I run:


truncate -s 0 /mydir/log.out
nohup longcommand.sh  > /mydir/log.out 2>&1 &
PID=`echo $!`
echo "$PID"
for (( ; ; ))
do
sleep 30
if ps -p $PID > /dev/null
then
echo "longcommand running"
else
echo "longcommand executed"
break
fi
done
cat /mydir/log.out

If you compare the original solution to mine i just deleted 0<&-.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s