Search in sources :

Example 1 with DirectoryEnvironmentConfig

use of org.opends.server.types.DirectoryEnvironmentConfig in project OpenAM by OpenRock.

the class EmbeddedOpenDS method startServer.

/**
     * Starts the embedded <code>OpenDJ</code> instance.
     *
     * @param odsRoot File system directory where <code>OpenDJ</code>
     *                is installed.
     * @throws Exception upon encountering errors.
     */
public static void startServer(String odsRoot) throws Exception {
    if (isStarted()) {
        return;
    }
    Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
    debug.message("EmbeddedOpenDS.startServer(" + odsRoot + ")");
    DirectoryEnvironmentConfig config = new DirectoryEnvironmentConfig();
    config.setServerRoot(new File(odsRoot));
    config.setForceDaemonThreads(true);
    config.setConfigClass(ConfigFileHandler.class);
    config.setConfigFile(new File(odsRoot + "/config", "config.ldif"));
    debug.message("EmbeddedOpenDS.startServer:starting DS Server...");
    EmbeddedUtils.startServer(config);
    debug.message("...EmbeddedOpenDS.startServer:DS Server started.");
    int sleepcount = 0;
    while (!EmbeddedUtils.isRunning() && (sleepcount < 60)) {
        sleepcount++;
        SetupProgress.reportStart("emb.waitingforstarted", null);
        Thread.sleep(1000);
    }
    if (EmbeddedUtils.isRunning()) {
        SetupProgress.reportEnd("emb.success", null);
    } else {
        SetupProgress.reportEnd("emb.failed", null);
    }
    serverStarted = true;
    ShutdownManager shutdownMan = com.sun.identity.common.ShutdownManager.getInstance();
    shutdownMan.addShutdownListener(new ShutdownListener() {

        public void shutdown() {
            try {
                shutdownServer("Graceful Shutdown");
            } catch (Exception ex) {
                Debug debug = Debug.getInstance(SetupConstants.DEBUG_NAME);
                debug.error("EmbeddedOpenDS:shutdown hook failed", ex);
            }
        }
    }, ShutdownPriority.LOWEST);
}
Also used : ShutdownListener(org.forgerock.util.thread.listener.ShutdownListener) ShutdownManager(com.sun.identity.common.ShutdownManager) DirectoryEnvironmentConfig(org.opends.server.types.DirectoryEnvironmentConfig) ZipFile(java.util.zip.ZipFile) File(java.io.File) Debug(com.sun.identity.shared.debug.Debug) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) LdapException(org.forgerock.opendj.ldap.LdapException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) IOException(java.io.IOException)

Example 2 with DirectoryEnvironmentConfig

use of org.opends.server.types.DirectoryEnvironmentConfig in project midpoint by Evolveum.

the class OpenDJController method start.

/**
	 * Start the embedded OpenDJ directory server.
	 * 
	 * Configuration and databases from serverRoot location will be used.
	 * 
	 * @return
	 */
public InternalClientConnection start() {
    LOGGER.info("Starting OpenDJ server");
    DirectoryEnvironmentConfig envConfig = new DirectoryEnvironmentConfig();
    try {
        envConfig.setServerRoot(serverRoot);
        envConfig.setConfigFile(configFile);
    // envConfig.setDisableConnectionHandlers(true);
    } catch (InitializationException ex) {
        ex.printStackTrace();
        throw new RuntimeException("OpenDJ initialization failed", ex);
    }
    // Check if the server is already running
    if (EmbeddedUtils.isRunning()) {
        throw new RuntimeException("Server already running");
    } else {
        try {
            EmbeddedUtils.startServer(envConfig);
        } catch (ConfigException ex) {
            LOGGER.error("Possible OpenDJ misconfiguration: " + ex.getMessage(), ex);
            throw new RuntimeException("OpenDJ startup failed", ex);
        } catch (InitializationException ex) {
            LOGGER.error("OpenDJ startup failed", ex);
            throw new RuntimeException("OpenDJ startup failed", ex);
        }
    }
    internalConnection = InternalClientConnection.getRootConnection();
    if (internalConnection == null) {
        LOGGER.error("OpenDJ cannot get internal connection (null)");
        throw new RuntimeException("OpenDS cannot get internal connection (null)");
    }
    LOGGER.info("OpenDJ server started");
    return internalConnection;
}
Also used : ConfigException(org.opends.server.config.ConfigException) InitializationException(org.opends.server.types.InitializationException) DirectoryEnvironmentConfig(org.opends.server.types.DirectoryEnvironmentConfig)

Aggregations

DirectoryEnvironmentConfig (org.opends.server.types.DirectoryEnvironmentConfig)2 ShutdownManager (com.sun.identity.common.ShutdownManager)1 Debug (com.sun.identity.shared.debug.Debug)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ZipFile (java.util.zip.ZipFile)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 LdapException (org.forgerock.opendj.ldap.LdapException)1 ShutdownListener (org.forgerock.util.thread.listener.ShutdownListener)1 ConfigException (org.opends.server.config.ConfigException)1 InitializationException (org.opends.server.types.InitializationException)1