diff options
author | Joel Johnson <joel.johnson@issinc.com> | 2015-06-26 15:47:44 -0600 |
---|---|---|
committer | Joel Johnson <joel.johnson@issinc.com> | 2015-06-29 10:17:52 -0600 |
commit | 2f361800ae381f365c5f33fbc2c5e3ffd5b90e2b (patch) | |
tree | 0fb97ff14b945d45b501b15fb569c2401e44a79f /src/main/java/com/gitblit/GitBlitServer.java | |
parent | a909bf1333d9e9bcdc5e87a17642211e6fa8f036 (diff) | |
download | gitblit-2f361800ae381f365c5f33fbc2c5e3ffd5b90e2b.tar.gz gitblit-2f361800ae381f365c5f33fbc2c5e3ffd5b90e2b.zip |
if failed to bind to port, don't use socket
Diffstat (limited to 'src/main/java/com/gitblit/GitBlitServer.java')
-rw-r--r-- | src/main/java/com/gitblit/GitBlitServer.java | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/main/java/com/gitblit/GitBlitServer.java b/src/main/java/com/gitblit/GitBlitServer.java index a1fd071f..d56d9c0c 100644 --- a/src/main/java/com/gitblit/GitBlitServer.java +++ b/src/main/java/com/gitblit/GitBlitServer.java @@ -509,22 +509,25 @@ public class GitBlitServer { @Override public void run() { - logger.info("Shutdown Monitor listening on port " + socket.getLocalPort()); - Socket accept; - try { - accept = socket.accept(); - BufferedReader reader = new BufferedReader(new InputStreamReader( - accept.getInputStream())); - reader.readLine(); - logger.info(Constants.BORDER); - logger.info("Stopping " + Constants.NAME); - logger.info(Constants.BORDER); - server.stop(); - server.setStopAtShutdown(false); - accept.close(); - socket.close(); - } catch (Exception e) { - logger.warn("Failed to shutdown Jetty", e); + // Only run if the socket was able to be created (not already in use, failed to bind, etc.) + if (null != socket) { + logger.info("Shutdown Monitor listening on port " + socket.getLocalPort()); + Socket accept; + try { + accept = socket.accept(); + BufferedReader reader = new BufferedReader(new InputStreamReader( + accept.getInputStream())); + reader.readLine(); + logger.info(Constants.BORDER); + logger.info("Stopping " + Constants.NAME); + logger.info(Constants.BORDER); + server.stop(); + server.setStopAtShutdown(false); + accept.close(); + socket.close(); + } catch (Exception e) { + logger.warn("Failed to shutdown Jetty", e); + } } } } |