Ejemplo n.º 1
0
  @Override
  protected int executeCommand() throws CommandException, CommandValidationException {
    // if the local password isn't available, the instance isn't running
    // (localPassword is set by initInstance)
    File serverDir = getServerDirs().getServerDir();

    if (serverDir == null || !serverDir.isDirectory()) return noSuchInstance();

    if (getServerDirs().getLocalPassword() == null) return instanceNotRunning();

    String serverName = getServerDirs().getServerName();
    HostAndPort addr = getAdminAddress(serverName);
    programOpts.setHostAndPort(addr);

    logger.finer("StopInstance.stoppingMessage" + addr.getPort());

    if (!isRunning()) return instanceNotRunning();

    logger.finer("It's the correct Instance");
    return doRemoteCommand();
  }
Ejemplo n.º 2
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;
  }