Skip to content

Instantly share code, notes, and snippets.

@kohsuke
Created January 28, 2015 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kohsuke/7effbaa28f422c35b3d1 to your computer and use it in GitHub Desktop.
Save kohsuke/7effbaa28f422c35b3d1 to your computer and use it in GitHub Desktop.
ZD-21119
diff --git a/src/main/java/hudson/plugins/ec2/EC2ComputerLauncher.java b/src/main/java/hudson/plugins/ec2/EC2ComputerLauncher.java
index fc6e6f7..34afdae 100644
--- a/src/main/java/hudson/plugins/ec2/EC2ComputerLauncher.java
+++ b/src/main/java/hudson/plugins/ec2/EC2ComputerLauncher.java
@@ -104,7 +104,7 @@ public abstract class EC2ComputerLauncher extends ComputerLauncher {
logger.println(msg);
}
- launch(computer, logger, computer.describeInstance());
+ launch(computer, listener, computer.describeInstance());
} catch (AmazonClientException e) {
e.printStackTrace(listener.error(e.getMessage()));
} catch (IOException e) {
@@ -118,7 +118,7 @@ public abstract class EC2ComputerLauncher extends ComputerLauncher {
/**
* Stage 2 of the launch. Called after the EC2 instance comes up.
*/
- protected abstract void launch(EC2Computer computer, PrintStream logger, Instance inst)
+ protected abstract void launch(EC2Computer computer, TaskListener listener, Instance inst)
throws AmazonClientException, IOException, InterruptedException;
private static final Logger LOGGER = Logger.getLogger(EC2ComputerLauncher.class.getName());
diff --git a/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java b/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
index 22dc3bb..2e755a4 100644
--- a/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
+++ b/src/main/java/hudson/plugins/ec2/ssh/EC2UnixLauncher.java
@@ -27,11 +27,13 @@ import hudson.Util;
import hudson.ProxyConfiguration;
import hudson.model.Descriptor;
import hudson.model.Hudson;
+import hudson.model.TaskListener;
import hudson.plugins.ec2.EC2ComputerLauncher;
import hudson.plugins.ec2.EC2Cloud;
import hudson.plugins.ec2.EC2Computer;
import hudson.remoting.Channel;
import hudson.remoting.Channel.Listener;
+import hudson.slaves.CommandLauncher;
import hudson.slaves.ComputerLauncher;
import java.io.IOException;
@@ -40,6 +42,7 @@ import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
+import hudson.util.StreamTaskListener;
import jenkins.model.Jenkins;
import org.apache.commons.io.IOUtils;
@@ -73,12 +76,13 @@ public class EC2UnixLauncher extends EC2ComputerLauncher {
@Override
- protected void launch(EC2Computer computer, PrintStream logger, Instance inst) throws IOException, AmazonClientException, InterruptedException {
+ protected void launch(EC2Computer computer, TaskListener listener, Instance inst) throws IOException, AmazonClientException, InterruptedException {
final Connection bootstrapConn;
final Connection conn;
Connection cleanupConn = null; // java's code path analysis for final doesn't work that well.
boolean successful = false;
-
+ PrintStream logger = listener.getLogger();
+
try {
bootstrapConn = connectToSsh(computer, logger);
int bootstrapResult = bootstrap(bootstrapConn, computer, logger);
@@ -107,7 +111,7 @@ public class EC2UnixLauncher extends EC2ComputerLauncher {
String tmpDir = (Util.fixEmptyAndTrim(computer.getNode().tmpDir) != null ? computer.getNode().tmpDir : "/tmp");
logger.println("Creating tmp directory (" + tmpDir + ") if it does not exist");
- conn.exec("mkdir -p " + tmpDir, logger);
+ conn.exec("mkdir -p " + tmpDir, logger);
if(initScript!=null && initScript.trim().length()>0 && conn.exec("test -e ~/.hudson-run-init", logger) !=0) {
logger.println("Executing init script");
@@ -122,7 +126,7 @@ public class EC2UnixLauncher extends EC2ComputerLauncher {
int exitStatus = waitCompletion(sess);
if (exitStatus!=0) {
- logger.println("init script failed: exit code="+exitStatus);
+ logger.println("init script failed: exit code=" + exitStatus);
return;
}
sess.close();
@@ -166,18 +170,22 @@ public class EC2UnixLauncher extends EC2ComputerLauncher {
scp.put(Hudson.getInstance().getJnlpJars("slave.jar").readFully(),
"slave.jar",tmpDir);
- String jvmopts = computer.getNode().jvmopts;
- String launchString = "java " + (jvmopts != null ? jvmopts : "") + " -jar " + tmpDir + "/slave.jar";
- logger.println("Launching slave agent: " + launchString);
- final Session sess = conn.openSession();
- sess.execCommand(launchString);
- computer.setChannel(sess.getStdout(),sess.getStdin(),logger,new Listener() {
- @Override
- public void onClosed(Channel channel, IOException cause) {
- sess.close();
- conn.close();
- }
- });
+ if (true) {
+ String jvmopts = computer.getNode().jvmopts;
+ String launchString = "java " + (jvmopts != null ? jvmopts : "") + " -jar " + tmpDir + "/slave.jar";
+ logger.println("Launching slave agent: " + launchString);
+ final Session sess = conn.openSession();
+ sess.execCommand(launchString);
+ computer.setChannel(sess.getStdout(), sess.getStdin(), logger, new Listener() {
+ @Override
+ public void onClosed(Channel channel, IOException cause) {
+ sess.close();
+ conn.close();
+ }
+ });
+ } else {
+ new CommandLauncher("ssh ... java ... -jar ").launch(computer,listener);
+ }
successful = true;
} finally {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment