From 09841d36e89fd0e52c949643c893e9e7bc891c6e Mon Sep 17 00:00:00 2001
From: Ludovic Poitou <ludovic.poitou@forgerock.com>
Date: Mon, 17 Oct 2016 06:49:28 +0000
Subject: [PATCH] Fix for OPENDJ-3273, detect the --quiet option for stop-ds and pass it down to avoid printing out the tail of the errors log.
---
opendj-server-legacy/src/main/java/org/opends/server/tools/StopDS.java | 22 ++++------
opendj-server-legacy/resource/bin/stop-ds | 22 +++++++++-
opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java | 29 ++++----------
3 files changed, 36 insertions(+), 37 deletions(-)
diff --git a/opendj-server-legacy/resource/bin/stop-ds b/opendj-server-legacy/resource/bin/stop-ds
index 75ca536..4af0007 100644
--- a/opendj-server-legacy/resource/bin/stop-ds
+++ b/opendj-server-legacy/resource/bin/stop-ds
@@ -77,6 +77,15 @@
fi
fi
+QUIET_OPTION=0
+for a in "$@"
+do
+ if [ "$a" = "--quiet" ]
+ then
+ QUIET_OPTION=1
+ fi
+done
+
# Set environment variables
SCRIPT_UTIL_CMD=set-full-server-environment-and-test-java
export SCRIPT_UTIL_CMD
@@ -154,9 +163,16 @@
EXIT_CODE=${?}
if test ${EXIT_CODE} -eq 0
then
- "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
- --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
- --logFile "${INSTANCE_ROOT}/logs/errors"
+ if test ${QUIET_OPTION} -eq 0
+ then
+ "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
+ --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
+ --logFile "${INSTANCE_ROOT}/logs/errors"
+ else
+ "${OPENDJ_JAVA_BIN}" -client org.opends.server.tools.WaitForFileDelete \
+ --targetFile "${INSTANCE_ROOT}/logs/server.pid" \
+ --logFile "${INSTANCE_ROOT}/logs/errors" --quiet
+ fi
EXIT_CODE=${?}
if test ${EXIT_CODE} -eq 0
then
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/StopDS.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/StopDS.java
index 2aee66e..48e1d6f 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/StopDS.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/StopDS.java
@@ -86,11 +86,10 @@
/** The fully-qualified name of this class. */
private static final String CLASS_NAME = "org.opends.server.tools.StopDS";
- /**
+ /*
* Return codes used when the hidden option --checkStoppability is used.
- * NOTE: when checkStoppability is specified is recommended not to allocate
- * a lot of memory for the JVM (Using -Xms and -Xmx options) as there might
- * be calls to Runtime.exec.
+ * NOTE: when checkStoppability is specified, it is recommended not to allocate a lot of memory for the JVM
+ * (Using -Xms and -Xmx options) as there might be calls to Runtime.exec.
*/
/** The server is already stopped. */
private static int SERVER_ALREADY_STOPPED = 98;
@@ -525,10 +524,10 @@
}
catch (LDAPConnectionException lce)
{
- LocalizableMessage message = null;
+ LocalizableMessage message;
if (lce.getCause() != null && lce.getCause().getCause() != null &&
lce.getCause().getCause() instanceof SSLException) {
- message = ERR_STOPDS_CANNOT_CONNECT_SSL.get(host.getValue(),
+ message = ERR_STOPDS_CANNOT_CONNECT_SSL.get(host.getValue(),
port.getValue());
} else {
String hostPort = host.getValue() + ":" + port.getValue();
@@ -562,13 +561,10 @@
attributes.add(new LDAPAttribute(ATTR_SHUTDOWN_MESSAGE, stopReason.getValue()));
}
- if (stopTime != null)
- {
- SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT_TIME);
- dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- String stopTimeValues = dateFormat.format(stopTime);
- attributes.add(new LDAPAttribute(ATTR_TASK_SCHEDULED_START_TIME, stopTimeValues));
- }
+ SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT_GMT_TIME);
+ dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
+ String stopTimeValues = dateFormat.format(stopTime);
+ attributes.add(new LDAPAttribute(ATTR_TASK_SCHEDULED_START_TIME, stopTimeValues));
ArrayList<Control> controls = new ArrayList<>();
if (proxyAuthzID.isPresent())
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
index 1282197..ced85e0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
@@ -143,13 +143,6 @@
* to be removed.
*
* @param args The command-line arguments provided to this program.
- * @param out The output stream to use for standard output, or
- * <CODE>null</CODE> if standard output is not
- * needed.
- * @param err The output stream to use for standard error, or
- * <CODE>null</CODE> if standard error is not
- * needed.
- * @param inStream The input stream to use for standard input.
*
* @return An integer value of zero if the file was deleted successfully, or
* some other value if a problem occurred.
@@ -206,7 +199,6 @@
.description(INFO_DSCORE_DESCRIPTION_LASTKNOWNGOODCFG.get())
.buildAndAddToParser(argParser);
- // Not used in this class, but required by the start-ds script (see issue #3814)
quietMode = quietArgument();
argParser.addArgument(quietMode);
@@ -276,7 +268,6 @@
// If an output file was specified and we could open the log file, open it
// and append data to it.
RandomAccessFile outputFile = null;
- long outputFileOffset = 0L;
if (logFile != null && outputFilePath.isPresent())
{
try
@@ -285,8 +276,7 @@
if (f.exists())
{
outputFile = new RandomAccessFile(f, "rw");
- outputFileOffset = outputFile.length();
- outputFile.seek(outputFileOffset);
+ outputFile.seek(outputFile.length());
}
}
catch (Exception e)
@@ -330,23 +320,20 @@
int bytesRead = logFile.read(logBuffer);
if (bytesRead > 0)
{
- if (outputFile == null)
+ if (outputFile != null)
+ {
+ outputFile.write(logBuffer, 0, bytesRead);
+ }
+ else if (!quietMode.isPresent())
{
getOutputStream().write(logBuffer, 0, bytesRead);
getOutputStream().flush();
}
- else
- {
- // Write on the file.
- // TODO
- outputFile.write(logBuffer, 0, bytesRead);
-
- }
logFileOffset += bytesRead;
}
}
}
- catch (Exception e)
+ catch (Exception ignored)
{
// We'll just ignore this.
}
@@ -362,7 +349,7 @@
try
{
Thread.sleep(10);
- } catch (InterruptedException ie) {}
+ } catch (InterruptedException ignored) {}
}
}
--
Gitblit v1.10.0