コード例 #1
0
 protected int installJava(Connection conn, PrintStream logger, Iterable<String> javaVersion)
     throws IOException, InterruptedException {
   int result = 1;
   for (String version : javaVersion) {
     result = conn.exec(getInstallCommand(version), logger);
     if (result == 0) {
       return result;
     }
   }
   return result;
 }
コード例 #2
0
  private boolean installJava(final PrintStream logger, final Connection conn)
      throws IOException, InterruptedException {
    logger.println("Verifying that java exists");
    if (conn.exec("java -fullversion", logger) != 0) {
      logger.println("Try to install one of these Java-versions: " + VALID_VERSIONS);
      // TODO Web UI to let users install a custom java (or any other type of tool) package.
      logger.println("Trying to find a working package manager");
      for (JavaInstaller installer : INSTALLERS) {
        if (!installer.isUsable(conn, logger)) {
          continue;
        }
        if (installer.installJava(conn, logger, VALID_VERSIONS) == 0) {
          return true;
        }
      }

      logger.println("Java could not be installed using any of the supported package managers");
      return false;
    }
    return true;
  }
コード例 #3
0
  private boolean runInitScript(
      final Computer computer, final PrintStream logger, final Connection conn, final SCPClient scp)
      throws IOException, InterruptedException {

    String initScript = Util.fixEmptyAndTrim(computer.getNode().getInitScript());

    if (initScript == null) {
      return true;
    }
    if (conn.exec("test -e ~/.hudson-run-init", logger) == 0) {
      return true;
    }

    logger.println("Executing init script");
    scp.put(initScript.getBytes("UTF-8"), "init.sh", "/tmp", "0700");
    Session session = conn.openSession();
    session.requestDumbPTY(); // so that the remote side bundles stdout and stderr
    session.execCommand(buildUpCommand(computer, "/tmp/init.sh"));

    session.getStdin().close(); // nothing to write here
    session.getStderr().close(); // we are not supposed to get anything from stderr
    IOUtils.copy(session.getStdout(), logger);

    int exitStatus = waitCompletion(session);
    if (exitStatus != 0) {
      logger.println("init script failed: exit code=" + exitStatus);
      return false;
    }
    session.close();

    // Needs a tty to run sudo.
    session = conn.openSession();
    session.requestDumbPTY(); // so that the remote side bundles stdout and stderr
    session.execCommand(buildUpCommand(computer, "touch ~/.hudson-run-init"));
    session.close();

    return true;
  }
コード例 #4
0
 private boolean checkCommand(Connection conn, PrintStream logger, String command)
     throws IOException, InterruptedException {
   logger.println("Checking: " + command);
   return conn.exec(command, logger) == 0;
 }