Esempio n. 1
0
    public static LocalDB initializeLocalDB(final PwmApplication pwmApplication) {
      if (pwmApplication.getApplicationMode() == MODE.ERROR
          || pwmApplication.getApplicationMode() == MODE.NEW) {
        LOGGER.warn(
            "skipping LocalDB open due to application mode " + pwmApplication.getApplicationMode());
        return null;
      }

      final File databaseDirectory;
      // see if META-INF isn't already there, then use WEB-INF.
      try {
        final String localDBLocationSetting =
            pwmApplication.getConfig().readSettingAsString(PwmSetting.PWMDB_LOCATION);
        databaseDirectory =
            Helper.figureFilepath(localDBLocationSetting, pwmApplication.applicationPath);
      } catch (Exception e) {
        pwmApplication.lastLocalDBFailure =
            new ErrorInformation(
                PwmError.ERROR_LOCALDB_UNAVAILABLE,
                "error locating configured LocalDB directory: " + e.getMessage());
        LOGGER.warn(pwmApplication.lastLocalDBFailure.toDebugStr());
        return null;
      }

      LOGGER.debug("using localDB path " + databaseDirectory);

      // initialize the localDB
      try {
        final boolean readOnly = pwmApplication.getApplicationMode() == MODE.READ_ONLY;
        return LocalDBFactory.getInstance(
            databaseDirectory, readOnly, pwmApplication, pwmApplication.getConfig());
      } catch (Exception e) {
        pwmApplication.lastLocalDBFailure =
            new ErrorInformation(
                PwmError.ERROR_LOCALDB_UNAVAILABLE,
                "unable to initialize LocalDB: " + e.getMessage());
        LOGGER.warn(pwmApplication.lastLocalDBFailure.toDebugStr());
      }

      return null;
    }
Esempio n. 2
0
  private void initialize(final boolean initLogging) throws PwmUnrecoverableException {
    final Date startTime = new Date();

    // initialize log4j
    if (initLogging) {
      final String log4jFileName =
          configuration.readSettingAsString(PwmSetting.EVENTS_JAVA_LOG4JCONFIG_FILE);
      final File log4jFile = Helper.figureFilepath(log4jFileName, applicationPath);
      final String consoleLevel, fileLevel;
      switch (getApplicationMode()) {
        case ERROR:
        case NEW:
          consoleLevel = PwmLogLevel.TRACE.toString();
          fileLevel = PwmLogLevel.TRACE.toString();
          break;

        default:
          consoleLevel = configuration.readSettingAsString(PwmSetting.EVENTS_JAVA_STDOUT_LEVEL);
          fileLevel = configuration.readSettingAsString(PwmSetting.EVENTS_FILE_LEVEL);
          break;
      }

      PwmLogManager.initializeLogger(
          this, configuration, log4jFile, consoleLevel, applicationPath, fileLevel);

      switch (getApplicationMode()) {
        case RUNNING:
          break;

        case ERROR:
          LOGGER.fatal(
              "starting up in ERROR mode! Check log or health check information for cause");
          break;

        default:
          LOGGER.trace(
              "setting log level to TRACE because application mode is " + getApplicationMode());
          break;
      }
    }

    LOGGER.info(
        "initializing, application mode="
            + getApplicationMode()
            + ", applicationPath="
            + (applicationPath == null ? "null" : applicationPath.getAbsolutePath())
            + ", configurationFile="
            + (configurationFile == null ? "null" : configurationFile.getAbsolutePath()));

    this.localDB = Initializer.initializeLocalDB(this);
    this.localDBLogger = PwmLogManager.initializeLocalDBLogger(this);

    // log the loaded configuration
    LOGGER.info("configuration load completed");

    // read the pwm servlet instance id
    instanceID = fetchInstanceID(localDB, this);
    LOGGER.info("using '" + getInstanceID() + "' for instance's ID (instanceID)");

    // read the pwm installation date
    installTime = fetchInstallDate(startupTime);
    LOGGER.debug(
        "this application instance first installed on "
            + PwmConstants.DEFAULT_DATETIME_FORMAT.format(installTime));

    initServices();

    final TimeDuration totalTime = TimeDuration.fromCurrent(startTime);
    LOGGER.info(
        PwmConstants.PWM_APP_NAME
            + " "
            + PwmConstants.SERVLET_VERSION
            + " open for bidness! ("
            + totalTime.asCompactString()
            + ")");
    StatisticsManager.incrementStat(this, Statistic.PWM_STARTUPS);
    LOGGER.debug(
        "buildTime="
            + PwmConstants.BUILD_TIME
            + ", javaLocale="
            + Locale.getDefault()
            + ", DefaultLocale="
            + PwmConstants.DEFAULT_LOCALE);

    final Thread postInitThread =
        new Thread() {
          @Override
          public void run() {
            postInitTasks();
          }
        };
    postInitThread.setDaemon(true);
    postInitThread.setName(Helper.makeThreadName(this, PwmApplication.class));
    postInitThread.start();
  }