You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2017/04/02 16:50:44 UTC
svn commit: r1789896 - in /directory/apacheds/trunk:
service/src/main/java/org/apache/directory/server/
service/src/test/java/org/apache/directory/server/
wrapper/src/main/java/org/apache/directory/server/wrapper/
Author: seelmann
Date: Sun Apr 2 16:50:44 2017
New Revision: 1789896
URL: http://svn.apache.org/viewvc?rev=1789896&view=rev
Log:
DIRSERVER-2186: Fix repair command
* Repair now only repairs and stops the service again
* Cleanup wrapper, shutdown port is not used
Modified:
directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/ApacheDsService.java
directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/UberjarMain.java
directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java
directory/apacheds/trunk/wrapper/src/main/java/org/apache/directory/server/wrapper/ApacheDsTanukiWrapper.java
Modified: directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/ApacheDsService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/ApacheDsService.java?rev=1789896&r1=1789895&r2=1789896&view=diff
==============================================================================
--- directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/ApacheDsService.java (original)
+++ directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/ApacheDsService.java Sun Apr 2 16:50:44 2017
@@ -234,7 +234,7 @@ public class ApacheDsService
/**
- * Try to repair the partitions. For each partition, we need its directory and its DN
+ * Try to repair the partitions. Precondition is that this service was started before.
*
* @param instanceLayout the on disk location's layout of the intance to be repaired
* @throws Exception If the repair failed
@@ -243,25 +243,8 @@ public class ApacheDsService
{
File partitionsDir = instanceLayout.getPartitionsDirectory();
- if ( !partitionsDir.exists() )
- {
- System.out.println( "partition directory doesn't exist, creating " + partitionsDir.getAbsolutePath() );
-
- if ( !partitionsDir.mkdirs() )
- {
- throw new IOException( I18n.err( I18n.ERR_112_COULD_NOT_CREATE_DIRECORY, partitionsDir ) );
- }
- }
-
System.out.println( "Repairing partition dir " + partitionsDir.getAbsolutePath() );
- CacheService cacheService = new CacheService();
- cacheService.initialize( instanceLayout );
-
- initSchemaManager( instanceLayout );
- DnFactory dnFactory = new DefaultDnFactory( schemaManager, cacheService.getCache( "dnCache" ) );
- initSchemaLdifPartition( instanceLayout, dnFactory );
- initConfigPartition( instanceLayout, dnFactory, cacheService );
Set<? extends Partition> partitions = getDirectoryService().getPartitions();
// Iterate on the partitions to repair them
Modified: directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/UberjarMain.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/UberjarMain.java?rev=1789896&r1=1789895&r2=1789896&view=diff
==============================================================================
--- directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/UberjarMain.java (original)
+++ directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/UberjarMain.java Sun Apr 2 16:50:44 2017
@@ -140,7 +140,7 @@ public class UberjarMain
public void start( String instanceDirectory )
{
InstanceLayout layout = new InstanceLayout( instanceDirectory );
-
+
// Creating ApacheDS service
service = new ApacheDsService();
@@ -149,7 +149,7 @@ public class UberjarMain
{
LOG.info( "Starting the service." );
service.start( layout );
-
+
startShutdownListener( layout );
}
catch ( Exception e )
@@ -170,22 +170,27 @@ public class UberjarMain
{
System.out.println( "Trying to repair the following data :" + instanceDirectory );
InstanceLayout layout = new InstanceLayout( instanceDirectory );
-
+
// Creating ApacheDS service
service = new ApacheDsService();
-
+
+ // Initializing the service
try
{
System.out.println( "Starting the service." );
- service.start( layout, false );
+ // must start servers otherwise stop() won't work
+ service.start( layout, true );
+ // no need to start the shutdown listener
System.out.println( "Service started." );
}
catch ( Exception e )
{
- return;
+ LOG.error( "Failed to start the service.", e );
+ stop();
+ System.exit( 1 );
}
- // Initializing the service
+ // Repairing the database
try
{
System.out.println( "Repairing the database." );
@@ -194,11 +199,15 @@ public class UberjarMain
}
catch ( Exception e )
{
- LOG.error( "Failed to start the service.", e );
+ LOG.error( "Failed to repair the database.", e );
+ stop();
System.exit( 1 );
}
+
+ // Stop the service
+ stop();
}
-
+
public void stop()
{
Modified: directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java?rev=1789896&r1=1789895&r2=1789896&view=diff
==============================================================================
--- directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java (original)
+++ directory/apacheds/trunk/service/src/test/java/org/apache/directory/server/UberJarMainTest.java Sun Apr 2 16:50:44 2017
@@ -360,12 +360,9 @@ public class UberJarMainTest
// Stop the server
uberjarMain.stop();
- // Try to repair it
+ // Try to repair it (also starts and stops the server)
uberjarMain.repair( instanceDirectory.toString() );
- // Stop the server again
- uberjarMain.stop();
-
// And restart it
connectionVerificationThread = createServer();
Modified: directory/apacheds/trunk/wrapper/src/main/java/org/apache/directory/server/wrapper/ApacheDsTanukiWrapper.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/wrapper/src/main/java/org/apache/directory/server/wrapper/ApacheDsTanukiWrapper.java?rev=1789896&r1=1789895&r2=1789896&view=diff
==============================================================================
--- directory/apacheds/trunk/wrapper/src/main/java/org/apache/directory/server/wrapper/ApacheDsTanukiWrapper.java (original)
+++ directory/apacheds/trunk/wrapper/src/main/java/org/apache/directory/server/wrapper/ApacheDsTanukiWrapper.java Sun Apr 2 16:50:44 2017
@@ -21,14 +21,6 @@
package org.apache.directory.server.wrapper;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.net.Socket;
-import java.nio.charset.Charset;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import org.apache.directory.api.util.Network;
import org.apache.directory.api.util.Strings;
import org.apache.directory.server.ApacheDsService;
import org.apache.directory.server.core.api.InstanceLayout;
@@ -66,23 +58,6 @@ public final class ApacheDsTanukiWrapper
}
-
- private static int readShutdownPort( InstanceLayout layout ) throws IOException
- {
- return Integer.parseInt( new String( Files.readAllBytes(
- Paths.get( layout.getRunDirectory().getAbsolutePath(), ".shutdown.port" ) ),
- Charset.forName( "utf-8" ) ) );
- }
-
-
- private static String readShutdownPassword( InstanceLayout layout ) throws IOException
- {
- return new String( Files.readAllBytes(
- Paths.get( layout.getRunDirectory().getAbsolutePath(), ".shutdown.pwd" ) ),
- Charset.forName( "utf-8" ) );
- }
-
-
/**
* Try to repair the databases
*
@@ -92,22 +67,26 @@ public final class ApacheDsTanukiWrapper
{
System.out.println( "Trying to repair the following data :" + instanceDirectory );
InstanceLayout layout = new InstanceLayout( instanceDirectory );
-
+
// Creating ApacheDS service
service = new ApacheDsService();
-
+
+ // Initializing the service
try
{
System.out.println( "Starting the service." );
- service.start( layout );
+ // must start servers otherwise stop() won't work
+ service.start( layout, true );
System.out.println( "Service started." );
}
catch ( Exception e )
{
- return;
+ LOG.error( "Failed to start the service.", e );
+ stop( 1 );
+ System.exit( ExitCodes.START );
}
- // Initializing the service
+ // Repairing the database
try
{
System.out.println( "Repairing the database." );
@@ -116,9 +95,13 @@ public final class ApacheDsTanukiWrapper
}
catch ( Exception e )
{
- LOG.error( "Failed to start the service.", e );
- System.exit( 1 );
+ LOG.error( "Failed to repair the database.", e );
+ stop( 1 );
+ System.exit( ExitCodes.START );
}
+
+ // Stop the service
+ stop( 0 );
}
@@ -169,32 +152,21 @@ public final class ApacheDsTanukiWrapper
// Process the action
switch ( Strings.toLowerCaseAscii( action ) )
{
- case "stop" :
+ case "stop":
// Stops the server
LOG.debug( "Stopping runtime" );
- InstanceLayout layout = new InstanceLayout( instanceDirectory );
-
- try ( Socket socket = new Socket( Network.LOOPBACK, readShutdownPort( layout ) );
- PrintWriter writer = new PrintWriter( socket.getOutputStream() ) )
- {
- writer.print( readShutdownPassword( layout ) );
- }
- catch ( IOException e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
+ stop( 1 );
+
break;
- case "repair" :
+ case "repair":
// Try to fix the JDBM database
LOG.debug( "Fixing the database runtime" );
repair( instanceDirectory );
-
+
break;
-
- default :
+
+ default:
// Starts the server
LOG.debug( "Starting runtime" );
@@ -207,7 +179,7 @@ public final class ApacheDsTanukiWrapper
LOG.error( "Failed to start the service.", e );
System.exit( ExitCodes.START );
}
-
+
break;
}