Beispiel #1
0
 @Override
 public void run() {
   Thread.currentThread().setName("DaemonShutdownThread");
   debug.fatal(
       "**************************************************************************************");
   debug.fatal(" JVM IS SHUTTING DOWN. KILLING CHILD PROCESS IF IT IS STILL ALIVE.");
   if (processThread != null && processThread.isAlive()) {
     debug.fatal("Process is still running. Shutting it down.");
     processThread.destroy();
   }
   debug.fatal(
       "**************************************************************************************");
 }
Beispiel #2
0
  private void start(final String args[]) {
    Thread.currentThread().setName("daemon_main");
    shutdownThread = new Daemon.DaemonShutdownHook();
    Runtime.getRuntime().addShutdownHook(shutdownThread); // To make sure the
    // child process is
    // killed on JVM-kill
    connectionThread = new Daemon.ManagerConnectionThread();
    connectionThread.start();

    processThread = new Daemon.ProcessThread(args);
    shutdownThread.setProcessThread(processThread);
    processThread.start();

    String oldServerBuildNumber = connectionThread.serverBuildNumber;
    while (true) {
      if (restartOnBuildNumberChange
          && !oldServerBuildNumber.equals(connectionThread.serverBuildNumber)) {
        debug.info(
            "**************************************************************************************");
        debug.info(
            "**************************************************************************************");
        debug.info(
            "Server has restarted and has a different build number... Restarting our child process.");

        if (processThread.isAlive()) {
          debug.info("Process is still running. Shutting it down.");
          processThread.destroy();
          try {
            Thread.sleep(5000);
          } catch (final InterruptedException ignored) {
          } // Let the process shut down...
        }
        debug.info(
            "**************************************************************************************");
        debug.info(
            "**************************************************************************************\n\n");

        if (jarSource != null && jarTarget != null) {
          try {
            debug.info("Copying newer jarfile '" + jarSource + "' to '" + jarTarget + "'");
            FileUtil.copy(new File(jarSource), new File(jarTarget), true);
            debug.info("Jar copied without error.");

            debug.debug("Asking the WrapperManager to restart the JVM... ");
            requestRestart();
          } catch (final IOException ex) {
            debug.error("Exception copying jar.", ex);
          }
        } else {
          debug.debug("Jar source and target were not specified. Jar copy skipped.");
        }

        processThread = new Daemon.ProcessThread(args);
        shutdownThread.setProcessThread(processThread);
        processThread.start();

        oldServerBuildNumber = connectionThread.serverBuildNumber;
      }
      try {
        Thread.sleep(5000);
      } catch (final InterruptedException ignored) {
      }
    }
  }