You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/01/16 08:34:03 UTC

[GitHub] jiazhai closed pull request #987: ISSUE #986: in LocalBK.main do Sys.exit in the case of an Exc

jiazhai closed pull request #987: ISSUE #986: in LocalBK.main do Sys.exit in the case of an Exc
URL: https://github.com/apache/bookkeeper/pull/987
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
index d4eccccbf..a735ed8f8 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java
@@ -407,41 +407,49 @@ private void serializeLocalBookieConfig(ServerConfiguration localBookieConfig, S
     }
 
     public static void main(String[] args) throws Exception, SecurityException {
-        if (args.length < 1) {
-            usage();
-            System.exit(-1);
-        }
+        try {
+            if (args.length < 1) {
+                usage();
+                System.exit(-1);
+            }
 
-        int numBookies = Integer.parseInt(args[0]);
+            int numBookies = Integer.parseInt(args[0]);
 
-        ServerConfiguration conf = new ServerConfiguration();
-        conf.setAllowLoopback(true);
-        if (args.length >= 2) {
-            String confFile = args[1];
-            try {
-                conf.loadConf(new File(confFile).toURI().toURL());
-                LOG.info("Using configuration file " + confFile);
-            } catch (Exception e) {
-                // load conf failed
-                LOG.warn("Error loading configuration file " + confFile, e);
+            ServerConfiguration conf = new ServerConfiguration();
+            conf.setAllowLoopback(true);
+            if (args.length >= 2) {
+                String confFile = args[1];
+                try {
+                    conf.loadConf(new File(confFile).toURI().toURL());
+                    LOG.info("Using configuration file " + confFile);
+                } catch (Exception e) {
+                    // load conf failed
+                    LOG.warn("Error loading configuration file " + confFile, e);
+                }
             }
-        }
 
-        String zkDataDir = null;
-        if (args.length >= 3) {
-            zkDataDir = args[2];
-        }
+            String zkDataDir = null;
+            if (args.length >= 3) {
+                zkDataDir = args[2];
+            }
 
-        String localBookiesConfigDirName = defaultLocalBookiesConfigDir;
-        if (args.length >= 4) {
-            localBookiesConfigDirName = args[3];
-        }
+            String localBookiesConfigDirName = defaultLocalBookiesConfigDir;
+            if (args.length >= 4) {
+                localBookiesConfigDirName = args[3];
+            }
 
-        startLocalBookiesInternal(
-                conf, zooKeeperDefaultHost, zooKeeperDefaultPort,
-                numBookies, true, bookieDefaultInitialPort,
-                false, "test",
-                zkDataDir, localBookiesConfigDirName);
+            startLocalBookiesInternal(conf, zooKeeperDefaultHost, zooKeeperDefaultPort, numBookies, true,
+                    bookieDefaultInitialPort, false, "test", zkDataDir, localBookiesConfigDirName);
+        } catch (Exception e) {
+            LOG.error("Exiting LocalBookKeeper because of exception in main method", e);
+            e.printStackTrace();
+            /*
+             * This is needed because, some non-daemon thread (probably in ZK or
+             * some other dependent service) is preventing the JVM from exiting, though
+             * there is exception in main thread.
+             */
+            System.exit(-1);
+        }
     }
 
     private static void usage() {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services