Skip to content

Commit 1651141

Browse files
authored
SOLR-18036 Auto migrate /var/solr/log4j2.xml when upgrading to Solr 10.x docker image (#3958)
1 parent 894fcbe commit 1651141

File tree

4 files changed

+178
-1
lines changed

4 files changed

+178
-1
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
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.
2+
type: other
3+
authors:
4+
- name: Jan Høydahl
5+
links:
6+
- name: SOLR-18036
7+
url: https://issues.apache.org/jira/browse/SOLR-18036
8+

solr/docker/scripts/init-var-solr

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ if [ ! -d "$DIR/logs" ]; then
5757
fi
5858

5959
if [ ! -f "$DIR/log4j2.xml" ]; then
60-
#echo "Copying log4j2.xml"
6160
cp -a /opt/solr/server/resources/log4j2.xml "$DIR/log4j2.xml"
61+
elif grep -q 'solr\.log\.dir' "$DIR/log4j2.xml"; then
62+
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
6263
fi
6364

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
<!-- Default production configuration is asynchronous logging -->
20+
<Configuration>
21+
<Appenders>
22+
23+
<Console name="STDOUT" target="SYSTEM_OUT">
24+
<PatternLayout>
25+
<Pattern>
26+
%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
27+
</Pattern>
28+
</PatternLayout>
29+
</Console>
30+
31+
<RollingRandomAccessFile
32+
name="MainLogFile"
33+
fileName="${sys:solr.log.dir}/solr.log"
34+
filePattern="${sys:solr.log.dir}/solr.log.%i" >
35+
<PatternLayout>
36+
<Pattern>
37+
%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
38+
</Pattern>
39+
</PatternLayout>
40+
<Policies>
41+
<OnStartupTriggeringPolicy />
42+
<SizeBasedTriggeringPolicy size="32 MB"/>
43+
</Policies>
44+
<DefaultRolloverStrategy max="10"/>
45+
</RollingRandomAccessFile>
46+
47+
<RollingRandomAccessFile
48+
name="SlowLogFile"
49+
fileName="${sys:solr.log.dir}/solr_slow_requests.log"
50+
filePattern="${sys:solr.log.dir}/solr_slow_requests.log.%i" >
51+
<PatternLayout>
52+
<Pattern>
53+
%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
54+
</Pattern>
55+
</PatternLayout>
56+
<Policies>
57+
<OnStartupTriggeringPolicy />
58+
<SizeBasedTriggeringPolicy size="32 MB"/>
59+
</Policies>
60+
<DefaultRolloverStrategy max="10"/>
61+
</RollingRandomAccessFile>
62+
63+
</Appenders>
64+
<Loggers>
65+
<!-- Use <AsyncLogger/<AsyncRoot and <Logger/<Root for asynchronous logging or synchronous logging respectively -->
66+
<AsyncLogger name="org.apache.hadoop" level="warn"/>
67+
<AsyncLogger name="org.apache.solr.update.LoggingInfoStream" level="off"/>
68+
<AsyncLogger name="org.apache.zookeeper" level="warn"/>
69+
<!-- HttpSolrCall adds markers denoting the handler class to allow fine grained control, metrics are
70+
very noisy so by default the metrics handler is turned off to see metrics logging set DENY to ACCEPT -->
71+
<AsyncLogger name="org.apache.solr.servlet.HttpSolrCall" level="info">
72+
<MarkerFilter marker="org.apache.solr.handler.admin.MetricsHandler" onMatch="DENY" onMismatch="ACCEPT"/>
73+
</AsyncLogger>
74+
<AsyncLogger name="org.apache.solr.core.SolrCore.SlowRequest" level="info" additivity="false">
75+
<AppenderRef ref="SlowLogFile"/>
76+
</AsyncLogger>
77+
<AsyncLogger name="org.eclipse.jetty.deploy" level="warn"/>
78+
<AsyncLogger name="org.eclipse.jetty.webapp" level="warn"/>
79+
<AsyncLogger name="org.eclipse.jetty.server.session" level="warn"/>
80+
81+
<AsyncRoot level="info">
82+
<AppenderRef ref="MainLogFile"/>
83+
<AppenderRef ref="STDOUT"/>
84+
</AsyncRoot>
85+
</Loggers>
86+
</Configuration>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
TEST_DIR="${TEST_DIR:-$(dirname -- "${BASH_SOURCE[0]}")}"
20+
source "${TEST_DIR}/../../shared.sh"
21+
22+
# Clean up any existing test containers and volumes
23+
container_cleanup "$container_name"
24+
docker volume rm "${container_name}-vol" 2>/dev/null || true
25+
26+
# Create a Docker volume
27+
echo "Creating Docker volume"
28+
docker volume create "${container_name}-vol"
29+
30+
# Use a temporary container to copy the old log4j2.xml into the volume
31+
echo "Copying old log4j2.xml into volume"
32+
docker run --rm \
33+
-v "${container_name}-vol:/var/solr" \
34+
-v "$TEST_DIR/log4j2_old.xml:/tmp/log4j2_old.xml:ro" \
35+
"$tag" \
36+
bash -c "cp /tmp/log4j2_old.xml /var/solr/log4j2.xml"
37+
38+
# Verify initial state - file should contain old property name
39+
echo "Verifying initial log4j2.xml contains old property name"
40+
old_log4j=$(docker run --rm -v "${container_name}-vol:/var/solr" -e NO_INIT_VAR_SOLR=1 "$tag" cat /var/solr/log4j2.xml)
41+
if ! grep -q 'solr\.log\.dir' <<<"$old_log4j"; then
42+
echo "Test setup failed; log4j2.xml does not contain solr.log.dir"
43+
docker volume rm "${container_name}-vol"
44+
exit 1
45+
fi
46+
echo "Confirmed: log4j2.xml contains solr.log.dir property"
47+
48+
# Start Solr with the volume (init-var-solr will run and migrate the file)
49+
echo "Running $container_name with volume"
50+
docker run --name "$container_name" -d \
51+
-v "${container_name}-vol:/var/solr" \
52+
"$tag" solr-precreate gettingstarted
53+
54+
wait_for_container_and_solr "$container_name"
55+
56+
# Verify the log4j2.xml has been migrated
57+
echo "Verifying log4j2.xml was migrated to new property name"
58+
migrated_log4j=$(docker exec "$container_name" cat /var/solr/log4j2.xml)
59+
60+
if grep -q 'solr\.log\.dir' <<<"$migrated_log4j"; then
61+
echo "Test $TEST_NAME $tag failed; log4j2.xml still contains old solr.log.dir property"
62+
docker exec "$container_name" cat /var/solr/log4j2.xml
63+
container_cleanup "$container_name"
64+
docker volume rm "${container_name}-vol"
65+
exit 1
66+
fi
67+
68+
if ! grep -q 'solr\.logs\.dir' <<<"$migrated_log4j"; then
69+
echo "Test $TEST_NAME $tag failed; log4j2.xml does not contain new solr.logs.dir property"
70+
docker exec "$container_name" cat /var/solr/log4j2.xml
71+
container_cleanup "$container_name"
72+
docker volume rm "${container_name}-vol"
73+
exit 1
74+
fi
75+
76+
echo "Confirmed: log4j2.xml successfully migrated from solr.log.dir to solr.logs.dir"
77+
78+
# Clean up
79+
container_cleanup "$container_name"
80+
docker volume rm "${container_name}-vol"
81+
82+
echo "Test $TEST_NAME $tag succeeded"

0 commit comments

Comments
 (0)