Skip to content

Commit

Permalink
Move existing logs in /opt/<component>/var/log to `/var/log/<compon…
Browse files Browse the repository at this point in the history
…ent>` 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
  • Loading branch information
zrhoffman authored Apr 30, 2024
1 parent e20656a commit b23c661
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 4 deletions.
19 changes: 18 additions & 1 deletion traffic_monitor/build/traffic_monitor.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion traffic_router/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@
<installScriptlet>
<!-- TODO: The /opt/traffic_router/var/log symlink is deprecated and should be removed
for ATC 9.0.0. -->
<script>ln -s /var/log/traffic_router %{buildroot}${deploy.dir}/var/log</script>
<script>ln -sfT /var/log/traffic_router %{buildroot}${deploy.dir}/var/log</script>
</installScriptlet>
<requires>
<require>java-11-openjdk-headless</require>
Expand Down
17 changes: 17 additions & 0 deletions traffic_router/core/src/main/scripts/preinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion traffic_router/tomcat-rpm/tomcat.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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/*
Expand All @@ -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
Expand Down
18 changes: 17 additions & 1 deletion traffic_stats/build/traffic_stats.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b23c661

Please sign in to comment.