Exemple #1
0
  /*
   * return 0 is success, otherwise failure
   */
  public final int runAdminCommandOnRemoteNode(
      Node thisNode, StringBuilder output, List<String> args, List<String> stdinLines)
      throws SSHCommandExecutionException, IllegalArgumentException, UnsupportedOperationException {

    String humanreadable = null;
    try {
      this.node = thisNode;
      dcomInfo = new DcomInfo(node);
      List<String> fullcommand = new ArrayList<String>();
      WindowsRemoteAsadmin asadmin = dcomInfo.getAsadmin();

      if (stdinLines != null && !stdinLines.isEmpty()) setupAuthTokenFile(fullcommand, stdinLines);

      fullcommand.addAll(args);
      humanreadable = dcomInfo.getNadminPath() + " " + commandListToString(fullcommand);

      // This is where the rubber meets the road...
      String out = asadmin.run(fullcommand);
      output.append(out);
      logger.info(Strings.get("remote.command.summary", humanreadable, out));
      return determineStatus(args);
    } catch (WindowsException ex) {
      throw new SSHCommandExecutionException(
          Strings.get("remote.command.error", ex.getMessage(), humanreadable), ex);
    } finally {
      teardownAuthTokenFile();
    }
  }
  /** Wait for the server to die. */
  private void waitForDeath() throws CommandException {
    if (!programOpts.isTerse()) {
      // use stdout because logger always appends a newline
      System.out.print(Strings.get("StopInstance.waitForDeath") + " ");
    }
    long startWait = System.currentTimeMillis();
    boolean alive = true;
    int count = 0;

    while (!timedOut(startWait)) {
      if (!isRunning()) {
        alive = false;
        break;
      }
      try {
        Thread.sleep(100);
        if (!programOpts.isTerse() && count++ % 10 == 0) System.out.print(".");
      } catch (InterruptedException ex) {
        // don't care
      }
    }

    if (!programOpts.isTerse()) System.out.println();

    if (alive) {
      throw new CommandException(
          Strings.get("StopInstance.instanceNotDead", (CLIConstants.DEATH_TIMEOUT_MS / 1000)));
    }
  }
Exemple #3
0
 private void teardownAuthTokenFile() {
   if (authTokenFile != null)
     try {
       authTokenFile.delete();
     } catch (WindowsException ex) {
       logger.warning(Strings.get("cant.delete", dcomInfo.getHost(), authTokenFilePath));
     }
 }
  /** Print message and return exit code when we detect that the DAS is not running. */
  protected int instanceNotRunning() throws CommandException {
    if (kill) return kill();

    // by definition this is not an error
    // https://glassfish.dev.java.net/issues/show_bug.cgi?id=8387

    logger.warning(Strings.get("StopInstance.instanceNotRunning"));
    return 0;
  }
  private int kill() throws CommandException {
    File prevPid = null;
    String pids = null;

    try {
      prevPid = new File(getServerDirs().getPidFile().getPath() + ".prev");

      if (!prevPid.canRead())
        throw new CommandException(Strings.get("StopInstance.nopidprev", prevPid));

      pids = FileUtils.readSmallFile(prevPid).trim();
      String s = ProcessUtils.kill(Integer.parseInt(pids));

      if (s != null) logger.finer(s);
    } catch (CommandException ce) {
      throw ce;
    } catch (Exception ex) {
      throw new CommandException(
          Strings.get("StopInstance.pidprevreaderror", prevPid, ex.getMessage()));
    }
    return 0;
  }
 /** Print message and return exit code when we detect that there is no such instance */
 private int noSuchInstance() {
   // by definition this is not an error
   // https://glassfish.dev.java.net/issues/show_bug.cgi?id=8387
   logger.warning(Strings.get("Instance.noSuchInstance"));
   return 0;
 }