Пример #1
0
  /**
   * Startups the RESTHeart server
   *
   * @param confFilePath the path of the configuration file
   */
  public static void startup(final Path confFilePath) {
    try {
      configuration = FileUtils.getConfiguration(confFilePath, false);
    } catch (ConfigurationException ex) {
      if (RESTHEART_VERSION != null) {
        LOGGER.info(
            ansi().fg(RED).bold().a("RESTHeart").reset().toString() + " version {}",
            RESTHEART_VERSION);
      }

      LOGGER.error(ex.getMessage() + ", exiting...", ex);
      stopServer(false);
      System.exit(-1);
    }

    startServer(false);
  }
Пример #2
0
  /**
   * main method
   *
   * @param args command line arguments
   */
  public static void main(final String[] args) {
    CONF_FILE_PATH = FileUtils.getConfigurationFilePath(args);

    try {
      // read configuration silently, to avoid logging before initializing the logger
      configuration = FileUtils.getConfiguration(args, true);
    } catch (ConfigurationException ex) {
      LOGGER.info("Starting " + ansi().fg(RED).bold().a("RESTHeart").reset().toString());

      if (RESTHEART_VERSION != null) {
        LOGGER.info("version {}", RESTHEART_VERSION);
      }

      LOGGER.error(ex.getMessage() + ", exiting...", ex);
      stopServer(false);
      System.exit(-1);
    }

    if (!hasForkOption(args)) {
      startServer(false);
    } else {
      if (OSChecker.isWindows()) {
        LOGGER.info("Starting " + ansi().fg(RED).bold().a("RESTHeart").reset().toString());

        if (RESTHEART_VERSION != null) {
          LOGGER.info("version {}", RESTHEART_VERSION);
        }

        LOGGER.error("Fork is not supported on Windows");

        LOGGER.info(ansi().fg(GREEN).bold().a("RESTHeart stopped").reset().toString());

        System.exit(-1);
      }

      // RHDaemon only works on POSIX OSes
      final boolean isPosix =
          FileSystems.getDefault().supportedFileAttributeViews().contains("posix");

      if (!isPosix) {
        LOGGER.info("Unable to fork process, " + "this is only supported on POSIX compliant OSes");

        stopServer(false);
        System.exit(-1);
      }

      RHDaemon d = new RHDaemon();

      if (d.isDaemonized()) {
        try {
          d.init();
          LOGGER.info("Forked process: {}", LIBC.getpid());
          initLogging(args, d);
        } catch (Throwable t) {
          LOGGER.error("Error staring forked process", t);
          stopServer(false, false);
          System.exit(-1);
        }

        startServer(true);
      } else {
        initLogging(args, d);

        try {
          LOGGER.info("Starting " + ansi().fg(RED).bold().a("RESTHeart").reset().toString());

          if (RESTHEART_VERSION != null) {
            LOGGER.info("version {}", RESTHEART_VERSION);
          }

          logLoggingConfiguration(true);

          d.daemonize();
        } catch (Throwable t) {
          LOGGER.error("Error forking", t);
          stopServer(false, false);
          System.exit(-1);
        }
      }
    }
  }