use of password.pwm.PwmEnvironment in project pwm by pwm-project.
the class ContextManager method initialize.
public void initialize() {
try {
Locale.setDefault(PwmConstants.DEFAULT_LOCALE);
} catch (Exception e) {
outputError("unable to set default locale as Java machine default locale: " + e.getMessage());
}
Configuration configuration = null;
PwmApplicationMode mode = PwmApplicationMode.ERROR;
final ParameterReader parameterReader = new ParameterReader(servletContext);
final File applicationPath;
{
final String applicationPathStr = parameterReader.readApplicationPath();
if (applicationPathStr == null || applicationPathStr.isEmpty()) {
startupErrorInformation = new ErrorInformation(PwmError.ERROR_ENVIRONMENT_ERROR, "application path is not specified");
return;
} else {
applicationPath = new File(applicationPathStr);
}
}
File configurationFile = null;
try {
configurationFile = locateConfigurationFile(applicationPath);
configReader = new ConfigurationReader(configurationFile);
configReader.getStoredConfiguration().lock();
configuration = configReader.getConfiguration();
mode = startupErrorInformation == null ? configReader.getConfigMode() : PwmApplicationMode.ERROR;
if (startupErrorInformation == null) {
startupErrorInformation = configReader.getConfigFileError();
}
if (PwmApplicationMode.ERROR == mode) {
outputError("Startup Error: " + (startupErrorInformation == null ? "un-specified error" : startupErrorInformation.toDebugStr()));
}
} catch (Throwable e) {
handleStartupError("unable to initialize application due to configuration related error: ", e);
}
LOGGER.debug("configuration file was loaded from " + (configurationFile == null ? "null" : configurationFile.getAbsoluteFile()));
final Collection<PwmEnvironment.ApplicationFlag> applicationFlags = parameterReader.readApplicationFlags();
final Map<PwmEnvironment.ApplicationParameter, String> applicationParams = parameterReader.readApplicationParams();
try {
final PwmEnvironment pwmEnvironment = new PwmEnvironment.Builder(configuration, applicationPath).setApplicationMode(mode).setConfigurationFile(configurationFile).setContextManager(this).setFlags(applicationFlags).setParams(applicationParams).createPwmEnvironment();
pwmApplication = new PwmApplication(pwmEnvironment);
} catch (Exception e) {
handleStartupError("unable to initialize application: ", e);
}
final String threadName = JavaHelper.makeThreadName(pwmApplication, this.getClass()) + " timer";
taskMaster = new Timer(threadName, true);
taskMaster.schedule(new RestartFlagWatcher(), 1031, 1031);
boolean reloadOnChange = true;
long fileScanFrequencyMs = 5000;
{
if (pwmApplication != null) {
reloadOnChange = Boolean.parseBoolean(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_RELOAD_ON_CHANGE));
fileScanFrequencyMs = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.CONFIG_FILE_SCAN_FREQUENCY));
}
if (reloadOnChange) {
taskMaster.schedule(new ConfigFileWatcher(), fileScanFrequencyMs, fileScanFrequencyMs);
}
checkConfigForSaveOnRestart(configReader, pwmApplication);
}
}
use of password.pwm.PwmEnvironment in project pwm by pwm-project.
the class DatabaseStatusChecker method checkDatabaseStatus.
private static List<HealthRecord> checkDatabaseStatus(final PwmApplication pwmApplication, final Configuration config) {
if (!config.hasDbConfigured()) {
return Collections.singletonList(new HealthRecord(HealthStatus.INFO, HealthTopic.Database, "Database not configured"));
}
PwmApplication runtimeInstance = null;
try {
final PwmEnvironment runtimeEnvironment = pwmApplication.getPwmEnvironment().makeRuntimeInstance(config);
runtimeInstance = new PwmApplication(runtimeEnvironment);
final DatabaseAccessor accessor = runtimeInstance.getDatabaseService().getAccessor();
accessor.get(DatabaseTable.PWM_META, "test");
return runtimeInstance.getDatabaseService().healthCheck();
} catch (PwmException e) {
LOGGER.error("error during healthcheck: " + e.getMessage());
e.printStackTrace();
return runtimeInstance.getDatabaseService().healthCheck();
} finally {
if (runtimeInstance != null) {
runtimeInstance.shutdown();
}
}
}
use of password.pwm.PwmEnvironment in project pwm by pwm-project.
the class MainClass method loadPwmApplication.
private static PwmApplication loadPwmApplication(final File applicationPath, final Collection<PwmEnvironment.ApplicationFlag> flags, final Configuration config, final File configurationFile, final boolean readonly) throws LocalDBException, PwmUnrecoverableException {
final PwmApplicationMode mode = readonly ? PwmApplicationMode.READ_ONLY : PwmApplicationMode.RUNNING;
final Collection<PwmEnvironment.ApplicationFlag> applicationFlags = new HashSet<>();
if (flags == null) {
applicationFlags.addAll(PwmEnvironment.ParseHelper.readApplicationFlagsFromSystem(null));
} else {
applicationFlags.addAll(flags);
}
applicationFlags.add(PwmEnvironment.ApplicationFlag.CommandLineInstance);
final PwmEnvironment pwmEnvironment = new PwmEnvironment.Builder(config, applicationPath).setApplicationMode(mode).setConfigurationFile(configurationFile).setFlags(applicationFlags).createPwmEnvironment();
final PwmApplication pwmApplication = new PwmApplication(pwmEnvironment);
final PwmApplicationMode runningMode = pwmApplication.getApplicationMode();
if (runningMode != mode) {
out("unable to start application in required state '" + mode + "', current state: " + runningMode);
System.exit(-1);
}
return pwmApplication;
}
Aggregations