You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by kr...@apache.org on 2016/10/20 19:31:14 UTC

[05/50] [abbrv] lucene-solr:jira/solr-8593: SOLR-9325: solr.log is now written to $SOLR_LOGS_DIR without changing log4j.properties

SOLR-9325: solr.log is now written to $SOLR_LOGS_DIR without changing log4j.properties


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/33db4de4
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/33db4de4
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/33db4de4

Branch: refs/heads/jira/solr-8593
Commit: 33db4de4d7d5e325f8bfd886d3957735b33310a8
Parents: 9304ef9
Author: Jan H�ydahl <ja...@apache.org>
Authored: Fri Oct 14 23:19:09 2016 +0200
Committer: Jan H�ydahl <ja...@apache.org>
Committed: Fri Oct 14 23:19:09 2016 +0200

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  2 ++
 solr/bin/solr                                   | 18 ++++++++++--
 solr/bin/solr.cmd                               | 31 ++++++++++++++++----
 solr/bin/solr.in.cmd                            |  3 ++
 solr/bin/solr.in.sh                             |  5 ++--
 .../apache/solr/servlet/SolrDispatchFilter.java |  1 +
 .../solr/servlet/StartupLoggingUtils.java       |  9 ++++++
 solr/server/resources/log4j.properties          |  2 +-
 8 files changed, 59 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 3280778..2bee12e 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -171,6 +171,8 @@ Bug Fixes
 * SOLR-9604: Pooled SSL connections were not being re-used (Alan Woodward,
   Mikhail Khludnev, hossman)
 
+* SOLR-9325: solr.log is now written to $SOLR_LOGS_DIR without changing log4j.properties (janhoy)
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/bin/solr
----------------------------------------------------------------------
diff --git a/solr/bin/solr b/solr/bin/solr
index f753d7d..90fffa1 100755
--- a/solr/bin/solr
+++ b/solr/bin/solr
@@ -1568,7 +1568,7 @@ function launch_solr() {
   fi
 
   SOLR_START_OPTS=('-server' "${JAVA_MEM_OPTS[@]}" "${GC_TUNE[@]}" "${GC_LOG_OPTS[@]}" \
-    "${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" $SOLR_LOG_LEVEL_OPT \
+    "${REMOTE_JMX_OPTS[@]}" "${CLOUD_MODE_OPTS[@]}" $SOLR_LOG_LEVEL_OPT -Dsolr.log.dir="$SOLR_LOGS_DIR" \
     "-Djetty.port=$SOLR_PORT" "-DSTOP.PORT=$stop_port" "-DSTOP.KEY=$STOP_KEY" \
     "${SOLR_HOST_ARG[@]}" "-Duser.timezone=$SOLR_TIMEZONE" \
     "-Djetty.home=$SOLR_SERVER_DIR" "-Dsolr.solr.home=$SOLR_HOME" "-Dsolr.install.dir=$SOLR_TIP" \
@@ -1578,7 +1578,21 @@ function launch_solr() {
     IN_CLOUD_MODE=" in SolrCloud mode"
   fi
 
-  mkdir -p "$SOLR_LOGS_DIR"
+  mkdir -p "$SOLR_LOGS_DIR" 2>/dev/null
+  if [ $? -ne 0 ]; then
+    echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR could not be created. Exiting"
+    exit 1
+  fi
+  if [ ! -w "$SOLR_LOGS_DIR" ]; then
+    echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR is not writable. Exiting"
+    exit 1
+  fi
+  case "$SOLR_LOGS_DIR" in
+    contexts|etc|lib|modules|resources|scripts|solr|solr-webapp)
+      echo -e "\nERROR: Logs directory $SOLR_LOGS_DIR is invalid. Reserved for the system. Exiting"
+      exit 1
+      ;;
+  esac
 
   if [ "$run_in_foreground" == "true" ]; then
     exec "$JAVA" "${SOLR_START_OPTS[@]}" $SOLR_ADDL_ARGS -jar start.jar "${SOLR_JETTY_CONFIG[@]}"

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/bin/solr.cmd
----------------------------------------------------------------------
diff --git a/solr/bin/solr.cmd b/solr/bin/solr.cmd
index 0bfb773..5376143 100644
--- a/solr/bin/solr.cmd
+++ b/solr/bin/solr.cmd
@@ -729,7 +729,13 @@ IF "%STOP_KEY%"=="" set STOP_KEY=solrrocks
 
 @REM This is quite hacky, but examples rely on a different log4j.properties
 @REM so that we can write logs for examples to %SOLR_HOME%\..\logs
-set "SOLR_LOGS_DIR=%SOLR_SERVER_DIR%\logs"
+IF [%SOLR_LOGS_DIR%] == [] (
+  set "SOLR_LOGS_DIR=%SOLR_SERVER_DIR%\logs"
+) ELSE (
+  set SOLR_LOGS_DIR=%SOLR_LOGS_DIR:"=%
+)
+set SOLR_LOGS_DIR_QUOTED="%SOLR_LOGS_DIR%"
+
 set "EXAMPLE_DIR=%SOLR_TIP%\example"
 set TMP=!SOLR_HOME:%EXAMPLE_DIR%=!
 IF NOT "%TMP%"=="%SOLR_HOME%" (
@@ -965,13 +971,26 @@ IF NOT "%SOLR_SSL_OPTS%"=="" (
   set "START_OPTS=%START_OPTS% %SOLR_SSL_OPTS% !SSL_PORT_PROP!"
 )
 IF NOT "%SOLR_LOG_LEVEL%"=="" set "START_OPTS=%START_OPTS% -Dsolr.log.level=%SOLR_LOG_LEVEL%"
-
+set "START_OPTS=%START_OPTS% -Dsolr.log.dir=%SOLR_LOGS_DIR_QUOTED%"
 IF NOT DEFINED LOG4J_CONFIG set "LOG4J_CONFIG=file:%SOLR_SERVER_DIR%\resources\log4j.properties"
 
 cd /d "%SOLR_SERVER_DIR%"
 
-IF NOT EXIST "!SOLR_LOGS_DIR!" (
-  mkdir "!SOLR_LOGS_DIR!"
+IF NOT EXIST "%SOLR_LOGS_DIR%" (
+  mkdir "%SOLR_LOGS_DIR%"
+)
+copy /Y NUL "%SOLR_LOGS_DIR%\.writable" > NUL 2>&1 && set WRITEOK=1
+IF DEFINED WRITEOK (
+  del "%SOLR_LOGS_DIR%\.writable"
+) else (
+  echo "ERROR: Logs directory %SOLR_LOGS_DIR% is not writable or could not be created. Exiting"
+  GOTO :eof
+)
+echo " contexts etc lib modules resources scripts solr solr-webapp " > "%TEMP%\solr-pattern.txt"
+findstr /i /C:" %SOLR_LOGS_DIR% " "%TEMP%\solr-pattern.txt" 1>nul
+if %ERRORLEVEL% == 0 (
+  echo "ERROR: Logs directory %SOLR_LOGS_DIR% is invalid. Reserved for the system. Exiting"
+  GOTO :eof
 )
 
 IF NOT EXIST "%SOLR_SERVER_DIR%\tmp" (
@@ -988,13 +1007,13 @@ IF "%FG%"=="1" (
   REM run solr in the foreground
   title "Solr-%SOLR_PORT%"
   echo %SOLR_PORT%>"%SOLR_TIP%"\bin\solr-%SOLR_PORT%.port
-  "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT%:"!SOLR_LOGS_DIR!"/solr_gc.log ^
+  "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% %GCLOG_OPT%:"!SOLR_LOGS_DIR!/solr_gc.log" ^
     -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! -DSTOP.KEY=%STOP_KEY% ^
     -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^
     -Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar "%SOLR_JETTY_CONFIG%"
 ) ELSE (
   START /B "Solr-%SOLR_PORT%" /D "%SOLR_SERVER_DIR%" "%JAVA%" %SERVEROPT% %SOLR_JAVA_MEM% %START_OPTS% ^
-    %GCLOG_OPT%:"!SOLR_LOGS_DIR!"/solr_gc.log -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! ^
+    %GCLOG_OPT%:"!SOLR_LOGS_DIR!/solr_gc.log" -Dlog4j.configuration="%LOG4J_CONFIG%" -DSTOP.PORT=!STOP_PORT! ^
     -Dsolr.log.muteconsole ^
     -DSTOP.KEY=%STOP_KEY% -Djetty.port=%SOLR_PORT% -Dsolr.solr.home="%SOLR_HOME%" -Dsolr.install.dir="%SOLR_TIP%" ^
     -Djetty.home="%SOLR_SERVER_DIR%" -Djava.io.tmpdir="%SOLR_SERVER_DIR%\tmp" -jar start.jar ^

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/bin/solr.in.cmd
----------------------------------------------------------------------
diff --git a/solr/bin/solr.in.cmd b/solr/bin/solr.in.cmd
index 07bffcc..5a2d00f 100644
--- a/solr/bin/solr.in.cmd
+++ b/solr/bin/solr.in.cmd
@@ -31,6 +31,9 @@ REM Changes the logging level. Valid values: ALL, TRACE, DEBUG, INFO, WARN, ERRO
 REM This is an alternative to changing the rootLogger in log4j.properties
 REM set SOLR_LOG_LEVEL=INFO
 
+REM Location where Solr should write logs to. Absolute or relative to solr start dir
+REM set SOLR_LOGS_DIR=logs
+
 REM These GC settings have shown to work well for a number of common Solr workloads
 set GC_TUNE=-XX:NewRatio=3 ^
  -XX:SurvivorRatio=4 ^

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/bin/solr.in.sh
----------------------------------------------------------------------
diff --git a/solr/bin/solr.in.sh b/solr/bin/solr.in.sh
index 999e673..dd41f46 100644
--- a/solr/bin/solr.in.sh
+++ b/solr/bin/solr.in.sh
@@ -96,9 +96,8 @@ SOLR_OPTS="$SOLR_OPTS -Xss256k"
 # This is an alternative to changing the rootLogger in log4j.properties
 #SOLR_LOG_LEVEL=INFO
 
-# Location where Solr should write logs to; should agree with the file appender
-# settings in server/resources/log4j.properties
-#SOLR_LOGS_DIR=
+# Location where Solr should write logs to. Absolute or relative to solr start dir
+#SOLR_LOGS_DIR=logs
 
 # Sets the port Solr binds to, default is 8983
 #SOLR_PORT=8983

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
index 241749a..b9d3729 100644
--- a/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
+++ b/solr/core/src/java/org/apache/solr/servlet/SolrDispatchFilter.java
@@ -123,6 +123,7 @@ public class SolrDispatchFilter extends BaseSolrFilter {
   {
     log.trace("SolrDispatchFilter.init(): {}", this.getClass().getClassLoader());
 
+    StartupLoggingUtils.checkLogDir();
     logWelcomeBanner();
     String muteConsole = System.getProperty(SOLR_LOG_MUTECONSOLE);
     if (muteConsole != null && !Arrays.asList("false","0","off","no").contains(muteConsole.toLowerCase(Locale.ROOT))) {

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/core/src/java/org/apache/solr/servlet/StartupLoggingUtils.java
----------------------------------------------------------------------
diff --git a/solr/core/src/java/org/apache/solr/servlet/StartupLoggingUtils.java b/solr/core/src/java/org/apache/solr/servlet/StartupLoggingUtils.java
index feb88e9..3da0841 100644
--- a/solr/core/src/java/org/apache/solr/servlet/StartupLoggingUtils.java
+++ b/solr/core/src/java/org/apache/solr/servlet/StartupLoggingUtils.java
@@ -41,6 +41,15 @@ final class StartupLoggingUtils {
   private final static StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
 
   /**
+   * Checks whether mandatory log dir is given
+   */
+  static void checkLogDir() {
+    if (System.getProperty("solr.log.dir") == null) {
+      log.error("Missing Java Option solr.log.dir. Logging may be missing or incomplete.");
+    }
+  }
+
+  /**
    * Disables all log4j ConsoleAppender's by modifying log4j configuration dynamically.
    * Must only be used during early startup
    * @return true if ok or else false if something happened, e.g. log4j classes were not in classpath

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/33db4de4/solr/server/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/solr/server/resources/log4j.properties b/solr/server/resources/log4j.properties
index 9a5e3fd..9f9c4a0 100644
--- a/solr/server/resources/log4j.properties
+++ b/solr/server/resources/log4j.properties
@@ -1,6 +1,6 @@
 # Default Solr log4j config
 # rootLogger log level may be programmatically overridden by -Dsolr.log.level
-solr.log=logs
+solr.log=${solr.log.dir}
 log4j.rootLogger=INFO, file, CONSOLE
 
 # Console appender will be programmatically disabled when Solr is started with option -Dsolr.log.muteconsole