From b23c661f155d36adb9a4a149e131cb7aa31ac319 Mon Sep 17 00:00:00 2001 From: Zach Hoffman Date: Tue, 30 Apr 2024 09:23:44 -0600 Subject: [PATCH] Move existing logs in `/opt//var/log` to `/var/log/` pre-upgrade (#8001) * Do not create a symlink inside the target if it already exists * Idempotently replace existing symlink if it exists * Move existing logs to the new log location, if they exist --- traffic_monitor/build/traffic_monitor.spec | 19 ++++++++++++++++++- traffic_router/build/pom.xml | 2 +- .../core/src/main/scripts/preinstall.sh | 17 +++++++++++++++++ traffic_router/tomcat-rpm/tomcat.spec | 17 ++++++++++++++++- traffic_stats/build/traffic_stats.spec | 18 +++++++++++++++++- 5 files changed, 69 insertions(+), 4 deletions(-) diff --git a/traffic_monitor/build/traffic_monitor.spec b/traffic_monitor/build/traffic_monitor.spec index f53520078b..3dbc548393 100644 --- a/traffic_monitor/build/traffic_monitor.spec +++ b/traffic_monitor/build/traffic_monitor.spec @@ -49,8 +49,9 @@ mkdir -p "${RPM_BUILD_ROOT}"/opt/traffic_monitor/backup mkdir -p "${RPM_BUILD_ROOT}"/opt/traffic_monitor/static mkdir -p "${RPM_BUILD_ROOT}"/opt/traffic_monitor/var/run mkdir -p "${RPM_BUILD_ROOT}"/var/log/traffic_monitor + # TODO: The /opt/traffic_monitor/var/log symlink is deprecated and should be removed for ATC 9.0.0. -ln -s /var/log/traffic_monitor "${RPM_BUILD_ROOT}"/opt/traffic_monitor/var/log +ln -sfT /var/log/traffic_monitor "${RPM_BUILD_ROOT}"/opt/traffic_monitor/var/log mkdir -p "${RPM_BUILD_ROOT}"/etc/init.d mkdir -p "${RPM_BUILD_ROOT}"/etc/logrotate.d @@ -65,6 +66,22 @@ cp "$src"/build/traffic_monitor.init "${RPM_BUILD_ROOT}"/etc/init.d/traffi cp "$src"/build/traffic_monitor.logrotate "${RPM_BUILD_ROOT}"/etc/logrotate.d/traffic_monitor %pre +old_log_dir=/opt/traffic_monitor/var/log +new_log_dir=/var/log/traffic_monitor +if [[ -d "$old_log_dir" ]]; then + if [[ -d "$new_log_dir" ]]; then + ( + # Include files starting with . in the * glob + shopt -s dotglob + mv "$old_log_dir"/* "$new_log_dir" || true + ) + rmdir "$old_log_dir" + else + mv "$old_log_dir" "$new_log_dir" + fi + sync +fi + /usr/bin/getent group traffic_monitor >/dev/null if [ $? -ne 0 ]; then /usr/sbin/groupadd -g 423 traffic_monitor diff --git a/traffic_router/build/pom.xml b/traffic_router/build/pom.xml index 25234b01e4..6a94ef7e9a 100644 --- a/traffic_router/build/pom.xml +++ b/traffic_router/build/pom.xml @@ -266,7 +266,7 @@ - + java-11-openjdk-headless diff --git a/traffic_router/core/src/main/scripts/preinstall.sh b/traffic_router/core/src/main/scripts/preinstall.sh index 89b540dff7..2905fdd005 100644 --- a/traffic_router/core/src/main/scripts/preinstall.sh +++ b/traffic_router/core/src/main/scripts/preinstall.sh @@ -13,6 +13,23 @@ # limitations under the License. # +set -o nounset +old_log_dir=/opt/traffic_router/var/log +new_log_dir=/var/log/traffic_router +if [[ -d "$old_log_dir" ]]; then + if [[ -d "$new_log_dir" ]]; then + ( + # Include files starting with . in the * glob + shopt -s dotglob + mv "$old_log_dir"/* "$new_log_dir" || true + ) + rmdir "$old_log_dir" + else + mv "$old_log_dir" "$new_log_dir" + fi + sync +fi + # figure out which version of traffic_router is currently running # and then shut it down. Running both test just in case. set +e diff --git a/traffic_router/tomcat-rpm/tomcat.spec b/traffic_router/tomcat-rpm/tomcat.spec index 3c66043e12..653194a25f 100644 --- a/traffic_router/tomcat-rpm/tomcat.spec +++ b/traffic_router/tomcat-rpm/tomcat.spec @@ -44,7 +44,7 @@ install -d -m 755 ${RPM_BUILD_ROOT}/%{tomcat_home}/ rmdir logs mkdir -p "${RPM_BUILD_ROOT}"/var/log/tomcat cp -R * ${RPM_BUILD_ROOT}/%{tomcat_home}/ -ln -s /var/log/tomcat "${RPM_BUILD_ROOT}"%{tomcat_home}/logs +ln -sfT /var/log/tomcat "${RPM_BUILD_ROOT}"%{tomcat_home}/logs # Remove all webapps. rm -rf ${RPM_BUILD_ROOT}/%{tomcat_home}/webapps/* @@ -70,6 +70,21 @@ if [ -d /opt/apache-tomcat-* ]; then fi %pre +old_log_dir=/opt/tomcat/logs +new_log_dir=/var/log/tomcat +if [[ -d "$old_log_dir" ]]; then + if [[ -d "$new_log_dir" ]]; then + ( + # Include files starting with . in the * glob + shopt -s dotglob + mv "$old_log_dir"/* "$new_log_dir" || true + ) + rmdir "$old_log_dir" + else + mv "$old_log_dir" "$new_log_dir" + fi + sync +fi %files %license LICENSE diff --git a/traffic_stats/build/traffic_stats.spec b/traffic_stats/build/traffic_stats.spec index c32e80bd6a..8fe85afddb 100644 --- a/traffic_stats/build/traffic_stats.spec +++ b/traffic_stats/build/traffic_stats.spec @@ -66,7 +66,7 @@ mkdir -p "${RPM_BUILD_ROOT}"/opt/traffic_stats/influxdb_tools mkdir -p "${RPM_BUILD_ROOT}"/opt/traffic_stats/var/run mkdir -p "${RPM_BUILD_ROOT}"/var/log/traffic_stats # TODO: The /opt/traffic_stats/var/log symlink is deprecated and should be removed for ATC 9.0.0. -ln -s /var/log/traffic_stats "${RPM_BUILD_ROOT}"/opt/traffic_stats/var/log +ln -sfT /var/log/traffic_stats "${RPM_BUILD_ROOT}"/opt/traffic_stats/var/log mkdir -p "${RPM_BUILD_ROOT}"/etc/init.d mkdir -p "${RPM_BUILD_ROOT}"/etc/logrotate.d mkdir -p "${RPM_BUILD_ROOT}"/var/lib/grafana/plugins/trafficcontrol-scenes-app @@ -83,6 +83,22 @@ cp "$src"/influxdb_tools/create_ts_databases "${RPM_BUILD_ROOT}"/opt/traffic_st %pre +old_log_dir=/opt/traffic_stats/var/log +new_log_dir=/var/log/traffic_stats +if [[ -d "$old_log_dir" ]]; then + if [[ -d "$new_log_dir" ]]; then + ( + # Include files starting with . in the * glob + shopt -s dotglob + mv "$old_log_dir"/* "$new_log_dir" || true + ) + rmdir "$old_log_dir" + else + mv "$old_log_dir" "$new_log_dir" + fi + sync +fi + /usr/bin/getent group traffic_stats >/dev/null if [ $? -ne 0 ]; then