directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r1691123 - /directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/UberjarMain.java
Date Wed, 15 Jul 2015 03:18:25 GMT
Author: kayyagari
Date: Wed Jul 15 03:18:24 2015
New Revision: 1691123

URL: http://svn.apache.org/r1691123
Log:
stop the service gracefully if the shutdown listener didn't start

Modified:
    directory/apacheds/trunk/service/src/main/java/org/apache/directory/server/UberjarMain.java

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=1691123&r1=1691122&r2=1691123&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
Wed Jul 15 03:18:24 2015
@@ -137,6 +137,7 @@ public class UberjarMain
         catch ( Exception e )
         {
             LOG.error( "Failed to start the service.", e );
+            stop();
             System.exit( 1 );
         }
     }
@@ -171,62 +172,67 @@ public class UberjarMain
         final int shutdownPort = getShutdownPort();
         final String shutdownPassword = writeShutdownPassword( layout, UUID.randomUUID().toString()
);
         
-        try {
-            new Thread( new Runnable()
+        new Thread( new Runnable()
+        {
+            @Override
+            public void run()
             {
-                @Override
-                public void run()
+                // bind to localhost only to prevent connections from outside the box
+                try ( ServerSocket shutdownSocket = new ServerSocket( shutdownPort, 1, InetAddress.getByName(
"localhost" ) ) )
                 {
-                    // bind to localhost only to prevent connections from outside the box
-                    try ( ServerSocket shutdownSocket = new ServerSocket( shutdownPort, 1,
InetAddress.getByName( "localhost" ) ) )
+                    writeShutdownPort( layout, shutdownSocket.getLocalPort() );
+                    
+                    LOG.info( "Start the shutdown listener on port {}", shutdownSocket.getLocalPort()
);
+                    
+                    Socket socket;
+                    while ( (socket = shutdownSocket.accept()) != null )
                     {
-                        writeShutdownPort( layout, shutdownSocket.getLocalPort() );
-                        
-                        LOG.info( "Start the shutdown listener on port [{}]", shutdownSocket.getLocalPort()
);
-                        
-                        Socket socket;
-                        while ( (socket = shutdownSocket.accept()) != null )
+                        if ( shutdownPassword == null || shutdownPassword.isEmpty() ) 
                         {
-                            if ( shutdownPassword == null || shutdownPassword.isEmpty() )

-                            {
-                                stop();
-                                break;
-                            }
-                            else
+                            stop();
+                            break;
+                        }
+                        else
+                        {
+                            try
                             {
-                                try ( InputStreamReader reader = new InputStreamReader( socket.getInputStream()
) )
+                                InputStreamReader reader = new InputStreamReader( socket.getInputStream()
);
+                                
+                                CharBuffer buffer = CharBuffer.allocate( 2048 );
+                                while ( reader.read( buffer ) >= 0 );
+                                buffer.flip();
+                                String password = buffer.toString();
+                                
+                                reader.close();
+                                
+                                if ( shutdownPassword.equals( password ) )
+                                {
+                                    stop();
+                                    break;
+                                }
+                                else
                                 {
-                                    CharBuffer buffer = CharBuffer.allocate( 2048 );
-                                    while ( reader.read( buffer ) >= 0 );
-                                    buffer.flip();
-                                    String password = buffer.toString();
-                                    if ( shutdownPassword.equals( password ) )
-                                    {
-                                        stop();
-                                        break;
-                                    }
-                                    else
-                                    {
-                                        LOG.warn( "Illegal attempt to shutdown, incorrect
password [{}]", password );
-                                    }
+                                    LOG.warn( "Illegal attempt to shutdown, incorrect password
{}", password );
                                 }
                             }
+                            catch ( IOException e )
+                            {
+                                LOG.warn( "Failed to handle the shutdown request", e );
+                            }
                         }
                     }
-                    catch ( IOException e )
-                    {
-                        LOG.error( "Failed to start the shutdown listener.", e );
-                    }
-                    
                 }
-            } ).start();
-        }
-        catch ( Exception e ) {
-            LOG.error( "Failed to start the shutdown listener.", e );
-            System.exit( 1 );
-        }
+                catch ( IOException e )
+                {
+                    LOG.error( "Failed to start the shutdown listener, stopping the server",
e );
+                    stop();
+                }
+                
+            }
+        } ).start();
     }
     
+    
     private static String writeShutdownPassword( InstanceLayout layout, String password )
throws IOException 
     {
         Files.write(



Mime
View raw message