From f1f8fc80ffd0d4aefccfba742e004060cafb23a0 Mon Sep 17 00:00:00 2001 From: Craig Silverstein Date: Mon, 20 Oct 2014 11:59:57 -0700 Subject: [PATCH] Restart slave.jar when it dies. Summary: Sometimes slave.jar dies due to an OOM error or the like. In those cases, make it automatically restart. Jenkins doesn't notice that slaves are dead in order to restart it themselves. Test Plan: Fingers crossed. I'll install this on jenkins, terminate all the jenkins-slave machines on ec2, and run make-allcheck, and make sure the slaves start up properly. I don't know what com.trilead.ssh2.Connection.execCommand does, but it looks like it just runs the given command in the shell, based on code example #6 at http://www.programcreek.com/java-api-examples/index.php?api=com.trilead.ssh2.Session >>> sess.execCommand("uname -a && date && uptime && who"); Reviewers: jlfwong Reviewed By: jlfwong Subscribers: chris Differential Revision: http://phabricator.khanacademy.org/D14010 --- src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java b/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java index b7435b538..69ce0aeb4 100644 --- a/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java +++ b/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java @@ -156,7 +156,7 @@ else if (bootstrapResult == SAMEUSER) { "slave.jar","/tmp"); String jvmopts = computer.getNode().jvmopts; - String launchString = "java " + (jvmopts != null ? jvmopts : "") + " -jar /tmp/slave.jar"; + String launchString = "while :; do java " + (jvmopts != null ? jvmopts : "") + " -jar /tmp/slave.jar; done"; logger.println("Launching slave agent: " + launchString); final Session sess = conn.openSession(); sess.execCommand(launchString);