Package org.springframework.util.exec

Examples of org.springframework.util.exec.Execute


      logger.info("Rabbit Process not running but status is ready.  Restarting.");
      stopNode();
    }

    logger.info("Starting RabbitMQ node by shelling out command line.");
    final Execute execute = new Execute();

    String rabbitStartScript = null;
    String hint = "";
    if (Os.isFamily("windows") || Os.isFamily("dos")) {
      rabbitStartScript = "sbin/rabbitmq-server.bat";
    } else if (Os.isFamily("unix") || Os.isFamily("mac")) {
      rabbitStartScript = "bin/rabbitmq-server";
      hint = "Depending on your platform it might help to set RABBITMQ_LOG_BASE and RABBITMQ_MNESIA_BASE System properties to an empty directory.";
    }
    Assert.notNull(rabbitStartScript, "unsupported OS family");

    String rabbitHome = System.getProperty("RABBITMQ_HOME", System.getenv("RABBITMQ_HOME"));
    if (rabbitHome == null) {
      if (Os.isFamily("windows") || Os.isFamily("dos")) {
        rabbitHome = findDirectoryName("c:/Program Files", "rabbitmq");
      } else if (Os.isFamily("unix") || Os.isFamily("mac")) {
        rabbitHome = "/usr/lib/rabbitmq";
      }
    }
    Assert.notNull(rabbitHome, "RABBITMQ_HOME system property (or environment variable) not set.");

    rabbitHome = StringUtils.cleanPath(rabbitHome);
    String rabbitStartCommand = rabbitHome + "/" + rabbitStartScript;
    String[] commandline = new String[] { rabbitStartCommand };

    List<String> env = new ArrayList<String>();

    if (rabbitLogBaseDirectory != null) {
      env.add("RABBITMQ_LOG_BASE=" + rabbitLogBaseDirectory);
    } else {
      addEnvironment(env, "RABBITMQ_LOG_BASE");
    }
    if (rabbitMnesiaBaseDirectory != null) {
      env.add("RABBITMQ_MNESIA_BASE=" + rabbitMnesiaBaseDirectory);
    } else {
      addEnvironment(env, "RABBITMQ_MNESIA_BASE");
    }
    addEnvironment(env, "ERLANG_HOME");

    // Make the nodename explicitly the same so the erl process knows who we are
    env.add("RABBITMQ_NODENAME=" + nodeName);

    // Set the port number for the new process
    env.add("RABBITMQ_NODE_PORT=" + port);

    // Ask for a detached erl process so stdout doesn't get diverted to a black hole when the JVM dies (without this
    // you can start the Rabbit broker form Java but if you forget to stop it, the erl process is hosed).
    env.add("RABBITMQ_SERVER_ERL_ARGS=-detached");

    execute.setCommandline(commandline);
    execute.setEnvironment(env.toArray(new String[0]));

    final CountDownLatch running = new CountDownLatch(1);
    final AtomicBoolean finished = new AtomicBoolean(false);
    final String errorHint = hint;

    executor.execute(new Runnable() {
      public void run() {
        try {
          running.countDown();
          int exit = execute.execute();
          finished.set(true);
          logger.info("Finished broker launcher process with exit code=" + exit);
          if (exit != 0) {
            throw new IllegalStateException("Could not start process." + errorHint);
          }
View Full Code Here

TOP

Related Classes of org.springframework.util.exec.Execute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.