This is an automated email from the ASF dual-hosted git repository.
janhoy pushed a commit to branch branch_10_0
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_10_0 by this push:
new 15fa74eb8f6 SOLR-18036 Auto migrate /var/solr/log4j2.xml when
upgrading to Solr 10.x docker image (#3958)
15fa74eb8f6 is described below
commit 15fa74eb8f6f6a58b6462067acee389446a658fb
Author: Jan Høydahl <[email protected]>
AuthorDate: Mon Dec 22 13:47:51 2025 +0100
SOLR-18036 Auto migrate /var/solr/log4j2.xml when upgrading to Solr 10.x
docker image (#3958)
(cherry picked from commit 16511419ae246b4c69ba9960f2eecc329c95c839)
---
.../SOLR-18036-auto-migrate-log4j2.xml-docker.yml | 8 ++
solr/docker/scripts/init-var-solr | 3 +-
.../tests/cases/log4j2_migration/log4j2_old.xml | 86 ++++++++++++++++++++++
solr/docker/tests/cases/log4j2_migration/test.sh | 82 +++++++++++++++++++++
4 files changed, 178 insertions(+), 1 deletion(-)
diff --git a/changelog/unreleased/SOLR-18036-auto-migrate-log4j2.xml-docker.yml
b/changelog/unreleased/SOLR-18036-auto-migrate-log4j2.xml-docker.yml
new file mode 100644
index 00000000000..1bf19f29ccd
--- /dev/null
+++ b/changelog/unreleased/SOLR-18036-auto-migrate-log4j2.xml-docker.yml
@@ -0,0 +1,8 @@
+title: Auto migrate /var/solr/log4j2.xml when starting the 10.x docker image.
It will change system property solr.log.dir to solr.logs.dir.
+type: other
+authors:
+ - name: Jan Høydahl
+links:
+ - name: SOLR-18036
+ url: https://issues.apache.org/jira/browse/SOLR-18036
+
diff --git a/solr/docker/scripts/init-var-solr
b/solr/docker/scripts/init-var-solr
index 3c6e25d42a5..d4a736f5f39 100755
--- a/solr/docker/scripts/init-var-solr
+++ b/solr/docker/scripts/init-var-solr
@@ -57,7 +57,8 @@ if [ ! -d "$DIR/logs" ]; then
fi
if [ ! -f "$DIR/log4j2.xml" ]; then
- #echo "Copying log4j2.xml"
cp -a /opt/solr/server/resources/log4j2.xml "$DIR/log4j2.xml"
+elif grep -q 'solr\.log\.dir' "$DIR/log4j2.xml"; then
+ sed -i 's/solr\.log\.dir/solr.logs.dir/g' "$DIR/log4j2.xml" 2>/dev/null ||
echo "Warning: Could not migrate solr.log.dir to solr.logs.dir in
$DIR/log4j2.xml" >&2
fi
diff --git a/solr/docker/tests/cases/log4j2_migration/log4j2_old.xml
b/solr/docker/tests/cases/log4j2_migration/log4j2_old.xml
new file mode 100644
index 00000000000..3d4626c15ad
--- /dev/null
+++ b/solr/docker/tests/cases/log4j2_migration/log4j2_old.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<!-- Default production configuration is asynchronous logging -->
+<Configuration>
+ <Appenders>
+
+ <Console name="STDOUT" target="SYSTEM_OUT">
+ <PatternLayout>
+ <Pattern>
+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t)
[%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{
r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.}
%m%notEmpty{ =>%ex{short}}}{10240}%n
+ </Pattern>
+ </PatternLayout>
+ </Console>
+
+ <RollingRandomAccessFile
+ name="MainLogFile"
+ fileName="${sys:solr.log.dir}/solr.log"
+ filePattern="${sys:solr.log.dir}/solr.log.%i" >
+ <PatternLayout>
+ <Pattern>
+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t)
[%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{
r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.}
%m%notEmpty{ =>%ex{short}}}{10240}%n
+ </Pattern>
+ </PatternLayout>
+ <Policies>
+ <OnStartupTriggeringPolicy />
+ <SizeBasedTriggeringPolicy size="32 MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="10"/>
+ </RollingRandomAccessFile>
+
+ <RollingRandomAccessFile
+ name="SlowLogFile"
+ fileName="${sys:solr.log.dir}/solr_slow_requests.log"
+ filePattern="${sys:solr.log.dir}/solr_slow_requests.log.%i" >
+ <PatternLayout>
+ <Pattern>
+ %maxLen{%d{yyyy-MM-dd HH:mm:ss.SSS} %-5p (%t)
[%notEmpty{c:%X{collection}}%notEmpty{ s:%X{shard}}%notEmpty{
r:%X{replica}}%notEmpty{ x:%X{core}}%notEmpty{ t:%X{trace_id}}] %c{1.}
%m%notEmpty{ =>%ex{short}}}{10240}%n
+ </Pattern>
+ </PatternLayout>
+ <Policies>
+ <OnStartupTriggeringPolicy />
+ <SizeBasedTriggeringPolicy size="32 MB"/>
+ </Policies>
+ <DefaultRolloverStrategy max="10"/>
+ </RollingRandomAccessFile>
+
+ </Appenders>
+ <Loggers>
+ <!-- Use <AsyncLogger/<AsyncRoot and <Logger/<Root for asynchronous
logging or synchronous logging respectively -->
+ <AsyncLogger name="org.apache.hadoop" level="warn"/>
+ <AsyncLogger name="org.apache.solr.update.LoggingInfoStream" level="off"/>
+ <AsyncLogger name="org.apache.zookeeper" level="warn"/>
+ <!-- HttpSolrCall adds markers denoting the handler class to allow fine
grained control, metrics are
+ very noisy so by default the metrics handler is turned off to see
metrics logging set DENY to ACCEPT -->
+ <AsyncLogger name="org.apache.solr.servlet.HttpSolrCall" level="info">
+ <MarkerFilter marker="org.apache.solr.handler.admin.MetricsHandler"
onMatch="DENY" onMismatch="ACCEPT"/>
+ </AsyncLogger>
+ <AsyncLogger name="org.apache.solr.core.SolrCore.SlowRequest" level="info"
additivity="false">
+ <AppenderRef ref="SlowLogFile"/>
+ </AsyncLogger>
+ <AsyncLogger name="org.eclipse.jetty.deploy" level="warn"/>
+ <AsyncLogger name="org.eclipse.jetty.webapp" level="warn"/>
+ <AsyncLogger name="org.eclipse.jetty.server.session" level="warn"/>
+
+ <AsyncRoot level="info">
+ <AppenderRef ref="MainLogFile"/>
+ <AppenderRef ref="STDOUT"/>
+ </AsyncRoot>
+ </Loggers>
+</Configuration>
diff --git a/solr/docker/tests/cases/log4j2_migration/test.sh
b/solr/docker/tests/cases/log4j2_migration/test.sh
new file mode 100755
index 00000000000..3003a706049
--- /dev/null
+++ b/solr/docker/tests/cases/log4j2_migration/test.sh
@@ -0,0 +1,82 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+set -euo pipefail
+
+TEST_DIR="${TEST_DIR:-$(dirname -- "${BASH_SOURCE[0]}")}"
+source "${TEST_DIR}/../../shared.sh"
+
+# Clean up any existing test containers and volumes
+container_cleanup "$container_name"
+docker volume rm "${container_name}-vol" 2>/dev/null || true
+
+# Create a Docker volume
+echo "Creating Docker volume"
+docker volume create "${container_name}-vol"
+
+# Use a temporary container to copy the old log4j2.xml into the volume
+echo "Copying old log4j2.xml into volume"
+docker run --rm \
+ -v "${container_name}-vol:/var/solr" \
+ -v "$TEST_DIR/log4j2_old.xml:/tmp/log4j2_old.xml:ro" \
+ "$tag" \
+ bash -c "cp /tmp/log4j2_old.xml /var/solr/log4j2.xml"
+
+# Verify initial state - file should contain old property name
+echo "Verifying initial log4j2.xml contains old property name"
+old_log4j=$(docker run --rm -v "${container_name}-vol:/var/solr" -e
NO_INIT_VAR_SOLR=1 "$tag" cat /var/solr/log4j2.xml)
+if ! grep -q 'solr\.log\.dir' <<<"$old_log4j"; then
+ echo "Test setup failed; log4j2.xml does not contain solr.log.dir"
+ docker volume rm "${container_name}-vol"
+ exit 1
+fi
+echo "Confirmed: log4j2.xml contains solr.log.dir property"
+
+# Start Solr with the volume (init-var-solr will run and migrate the file)
+echo "Running $container_name with volume"
+docker run --name "$container_name" -d \
+ -v "${container_name}-vol:/var/solr" \
+ "$tag" solr-precreate gettingstarted
+
+wait_for_container_and_solr "$container_name"
+
+# Verify the log4j2.xml has been migrated
+echo "Verifying log4j2.xml was migrated to new property name"
+migrated_log4j=$(docker exec "$container_name" cat /var/solr/log4j2.xml)
+
+if grep -q 'solr\.log\.dir' <<<"$migrated_log4j"; then
+ echo "Test $TEST_NAME $tag failed; log4j2.xml still contains old
solr.log.dir property"
+ docker exec "$container_name" cat /var/solr/log4j2.xml
+ container_cleanup "$container_name"
+ docker volume rm "${container_name}-vol"
+ exit 1
+fi
+
+if ! grep -q 'solr\.logs\.dir' <<<"$migrated_log4j"; then
+ echo "Test $TEST_NAME $tag failed; log4j2.xml does not contain new
solr.logs.dir property"
+ docker exec "$container_name" cat /var/solr/log4j2.xml
+ container_cleanup "$container_name"
+ docker volume rm "${container_name}-vol"
+ exit 1
+fi
+
+echo "Confirmed: log4j2.xml successfully migrated from solr.log.dir to
solr.logs.dir"
+
+# Clean up
+container_cleanup "$container_name"
+docker volume rm "${container_name}-vol"
+
+echo "Test $TEST_NAME $tag succeeded"