core: improve log cleaning (#8999)

Co-authored-by: Tobias <96661824+CrazyWolf13@users.noreply.github.com>
This commit is contained in:
CanbiZ
2025-11-09 05:46:09 -08:00
committed by GitHub
parent 0e7be1dd1e
commit c0c5fd4532

View File

@@ -370,6 +370,7 @@ run_container_safe() {
cleanup_lxc() { cleanup_lxc() {
msg_info "Cleaning up" msg_info "Cleaning up"
if is_alpine; then if is_alpine; then
$STD apk cache clean || true $STD apk cache clean || true
rm -rf /var/cache/apk/* rm -rf /var/cache/apk/*
@@ -379,13 +380,15 @@ cleanup_lxc() {
$STD apt -y clean || true $STD apt -y clean || true
fi fi
rm -rf /tmp/* /var/tmp/* # Clear temp artifacts (keep sockets/FIFOs; ignore errors)
# Remove temp files created by mktemp/tempfile
find /tmp /var/tmp -type f -name 'tmp*' -delete 2>/dev/null || true find /tmp /var/tmp -type f -name 'tmp*' -delete 2>/dev/null || true
find /tmp /var/tmp -type f -name 'tempfile*' -delete 2>/dev/null || true find /tmp /var/tmp -type f -name 'tempfile*' -delete 2>/dev/null || true
find /var/log -type f -exec truncate -s 0 {} + # Truncate writable log files silently (permission errors ignored)
if command -v truncate >/dev/null 2>&1; then
find /var/log -type f -writable -print0 2>/dev/null | \
xargs -0 -n1 truncate -s 0 2>/dev/null || true
fi
# Python pip # Python pip
if command -v pip &>/dev/null; then pip cache purge || true; fi if command -v pip &>/dev/null; then pip cache purge || true; fi
@@ -407,8 +410,8 @@ cleanup_lxc() {
if command -v composer &>/dev/null; then composer clear-cache || true; fi if command -v composer &>/dev/null; then composer clear-cache || true; fi
if command -v journalctl &>/dev/null; then if command -v journalctl &>/dev/null; then
$STD journalctl --rotate $STD journalctl --rotate || true
$STD journalctl --vacuum-time=10m $STD journalctl --vacuum-time=10m || true
fi fi
msg_ok "Cleaned" msg_ok "Cleaned"
} }