private DirectoryService initDirectoryService(
      InstanceLayout instanceLayout,
      DirectoryServiceBean directoryServiceBean,
      CacheService cacheService)
      throws Exception {
    LOG.info("Initializing the DirectoryService...");

    long startTime = System.currentTimeMillis();

    DirectoryService directoryService =
        ServiceBuilder.createDirectoryService(directoryServiceBean, instanceLayout, schemaManager);

    // The schema partition
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(schemaLdifPartition);
    directoryService.setSchemaPartition(schemaPartition);

    directoryService.addPartition(configPartition);

    // Store the default directories
    directoryService.setInstanceLayout(instanceLayout);
    directoryService.setCacheService(cacheService);
    directoryService.startup();

    if (isConfigPartitionFirstExtraction) {
      LOG.info(
          "begining to update config partition LDIF files after modifying manadatory attributes");

      // disable writes to the disk upon every modification to improve performance
      configPartition.setEnableRewriting(false);

      // perform updates
      updateMandatoryOpAttributes(configPartition, directoryService);

      // enable writes to disk, this will save the partition data first if found dirty
      configPartition.setEnableRewriting(true);

      LOG.info("config partition data was successfully updated");
    }

    if (isSchemaPartitionFirstExtraction) {
      LOG.info(
          "begining to update schema partition LDIF files after modifying manadatory attributes");

      updateMandatoryOpAttributes(schemaLdifPartition, directoryService);

      LOG.info("schema partition data was successfully updated");
    }

    LOG.info(
        "DirectoryService initialized in {} milliseconds",
        (System.currentTimeMillis() - startTime));

    return directoryService;
  }
  /** {@inheritDoc} */
  public void init(String name) throws Exception {
    if ((directoryService != null) && directoryService.isStarted()) {
      return;
    }

    directoryService.setInstanceId(name);

    // instance layout
    InstanceLayout instanceLayout =
        new InstanceLayout(System.getProperty("java.io.tmpdir") + "/server-work-" + name);
    if (instanceLayout.getInstanceDirectory().exists()) {
      try {
        FileUtils.deleteDirectory(instanceLayout.getInstanceDirectory());
      } catch (IOException e) {
        LOG.warn(
            "couldn't delete the instance directory before initializing the DirectoryService", e);
      }
    }
    directoryService.setInstanceLayout(instanceLayout);

    // EhCache in disabled-like-mode
    Configuration ehCacheConfig = new Configuration();
    CacheConfiguration defaultCache =
        new CacheConfiguration("default", 1)
            .eternal(false)
            .timeToIdleSeconds(30)
            .timeToLiveSeconds(30)
            .overflowToDisk(false);
    ehCacheConfig.addDefaultCache(defaultCache);
    CacheService cacheService = new CacheService(new CacheManager(ehCacheConfig));
    directoryService.setCacheService(cacheService);

    // Init the schema
    // SchemaLoader loader = new SingleLdifSchemaLoader();
    SchemaLoader loader = new JarLdifSchemaLoader();
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    schemaManager.loadAllEnabled();
    ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
    for (LdapComparator<?> comparator : comparatorRegistry) {
      if (comparator instanceof NormalizingComparator) {
        ((NormalizingComparator) comparator).setOnServer();
      }
    }
    directoryService.setSchemaManager(schemaManager);
    InMemorySchemaPartition inMemorySchemaPartition = new InMemorySchemaPartition(schemaManager);

    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(inMemorySchemaPartition);
    directoryService.setSchemaPartition(schemaPartition);
    List<Throwable> errors = schemaManager.getErrors();
    if (errors.size() != 0) {
      throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }

    // Init system partition
    Partition systemPartition =
        partitionFactory.createPartition(
            directoryService.getSchemaManager(),
            "system",
            ServerDNConstants.SYSTEM_DN,
            500,
            new File(directoryService.getInstanceLayout().getPartitionsDirectory(), "system"));
    systemPartition.setSchemaManager(directoryService.getSchemaManager());
    partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);
    directoryService.setSystemPartition(systemPartition);

    directoryService.startup();
  }