diff --git a/debian/cloudstack-management.postinst b/debian/cloudstack-management.postinst index d5d50a4718c3..0b6302a713ff 100755 --- a/debian/cloudstack-management.postinst +++ b/debian/cloudstack-management.postinst @@ -59,6 +59,33 @@ if [ "$1" = configure ]; then chown -R cloud:cloud /usr/share/cloudstack-management/templates find /usr/share/cloudstack-management/templates -type d -exec chmod 0770 {} \; + LOGFILE="${CONFDIR}/log4j-cloud.xml" + + # Detect if current file is old Log4j1 format + if grep -q "/dev/null; then + echo "Old Log4j1 format detected in $LOGFILE" + + BACKUP_SUFFIXES=".rpmnew .dpkg-new .dpkg-dist" + for sfx in $BACKUP_SUFFIXES; do + NEWFILE="${LOGFILE}${sfx}" + if [ -f "$NEWFILE" ]; then + echo "Found new version candidate: $NEWFILE" + + # Verify that the candidate actually has Log4j2 syntax + if grep -q "/dev/null; then + echo "Verified Log4j2 format in $NEWFILE — applying update." + cp -f "$NEWFILE" "$LOGFILE" + mv "$NEWFILE" "${NEWFILE}.bak.$(date +%F_%H-%M-%S)" + echo "Replaced old Log4j1 config with Log4j2 version." + break + else + echo "WARNING: $NEWFILE does not appear to be Log4j2 format — skipping." + fi + fi + done + else + echo "Log4j2 format already present — no action needed." + fi ln -sf ${CONFDIR}/log4j-cloud.xml ${CONFDIR}/log4j2.xml # Add jdbc MySQL driver settings to db.properties if not present diff --git a/debian/cloudstack-management.preinst b/debian/cloudstack-management.preinst index ebb98522d6f9..5b967d20f524 100755 --- a/debian/cloudstack-management.preinst +++ b/debian/cloudstack-management.preinst @@ -29,4 +29,14 @@ if [ "$1" = upgrade ]; then rm -f /usr/share/cloudstack-management/work rm -f /etc/default/cloudstack-management fi + + if [ -L "/etc/cloudstack/management/log4j.xml" ]; then + echo "Removing existing /etc/cloudstack/management/log4j.xml, symlink will again be created during post install" + rm -f /etc/cloudstack/management/log4j.xml + fi + + if [ -L "/etc/cloudstack/management/log4j2.xml" ]; then + echo "Removing existing /etc/cloudstack/management/log4j2.xml, symlink will again be created during post install" + rm -f /etc/cloudstack/management/log4j2.xml + fi fi