Skip to content

Commit d89db3e

Browse files
Add safe checks and make sure log4j configuration has log4j2 format
1 parent e90e31d commit d89db3e

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

debian/cloudstack-management.postinst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,34 @@ if [ "$1" = configure ]; then
6262
chmod -R 0755 /etc/cloudstack/extensions
6363
chown -R cloud:cloud /etc/cloudstack/extensions
6464

65+
LOGFILE="${CONFDIR}/log4j-cloud.xml"
66+
67+
# Detect if current file is old Log4j1 format
68+
if grep -q "<log4j:configuration" "$LOGFILE" 2>/dev/null; then
69+
echo "Old Log4j1 format detected in $LOGFILE"
70+
71+
BACKUP_SUFFIXES=".rpmnew .dpkg-new .dpkg-dist"
72+
for sfx in $BACKUP_SUFFIXES; do
73+
NEWFILE="${LOGFILE}${sfx}"
74+
if [ -f "$NEWFILE" ]; then
75+
echo "Found new version candidate: $NEWFILE"
76+
77+
# Verify that the candidate actually has Log4j2 syntax
78+
if grep -q "<Configuration" "$NEWFILE" 2>/dev/null; then
79+
echo "Verified Log4j2 format in $NEWFILE — applying update."
80+
cp -f "$NEWFILE" "$LOGFILE"
81+
mv "$NEWFILE" "${NEWFILE}.bak.$(date +%F_%H-%M-%S)"
82+
echo "Replaced old Log4j1 config with Log4j2 version."
83+
break
84+
else
85+
echo "WARNING: $NEWFILE does not appear to be Log4j2 format — skipping."
86+
fi
87+
fi
88+
done
89+
else
90+
echo "Log4j2 format already present — no action needed."
91+
fi
92+
6593
ln -sf ${CONFDIR}/log4j-cloud.xml ${CONFDIR}/log4j2.xml
6694

6795
# Add jdbc MySQL driver settings to db.properties if not present

debian/cloudstack-management.preinst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,14 @@ if [ "$1" = upgrade ]; then
2929
rm -f /usr/share/cloudstack-management/work
3030
rm -f /etc/default/cloudstack-management
3131
fi
32+
33+
if [ -L "/etc/cloudstack/management/log4j.xml" ]; then
34+
echo "Removing existing /etc/cloudstack/management/log4j.xml, symlink will again be created during post install"
35+
rm -f /etc/cloudstack/management/log4j.xml
36+
fi
37+
38+
if [ -L "/etc/cloudstack/management/log4j2.xml" ]; then
39+
echo "Removing existing /etc/cloudstack/management/log4j2.xml, symlink will again be created during post install"
40+
rm -f /etc/cloudstack/management/log4j2.xml
41+
fi
3242
fi

0 commit comments

Comments
 (0)