Skip to content

Commit c0c5fd4

Browse files
core: improve log cleaning (#8999)
Co-authored-by: Tobias <[email protected]>
1 parent 0e7be1d commit c0c5fd4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

misc/core.func

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ run_container_safe() {
370370

371371
cleanup_lxc() {
372372
msg_info "Cleaning up"
373+
373374
if is_alpine; then
374375
$STD apk cache clean || true
375376
rm -rf /var/cache/apk/*
@@ -379,13 +380,15 @@ cleanup_lxc() {
379380
$STD apt -y clean || true
380381
fi
381382

382-
rm -rf /tmp/* /var/tmp/*
383-
384-
# Remove temp files created by mktemp/tempfile
383+
# Clear temp artifacts (keep sockets/FIFOs; ignore errors)
385384
find /tmp /var/tmp -type f -name 'tmp*' -delete 2>/dev/null || true
386385
find /tmp /var/tmp -type f -name 'tempfile*' -delete 2>/dev/null || true
387386

388-
find /var/log -type f -exec truncate -s 0 {} +
387+
# Truncate writable log files silently (permission errors ignored)
388+
if command -v truncate >/dev/null 2>&1; then
389+
find /var/log -type f -writable -print0 2>/dev/null | \
390+
xargs -0 -n1 truncate -s 0 2>/dev/null || true
391+
fi
389392

390393
# Python pip
391394
if command -v pip &>/dev/null; then pip cache purge || true; fi
@@ -407,8 +410,8 @@ cleanup_lxc() {
407410
if command -v composer &>/dev/null; then composer clear-cache || true; fi
408411

409412
if command -v journalctl &>/dev/null; then
410-
$STD journalctl --rotate
411-
$STD journalctl --vacuum-time=10m
413+
$STD journalctl --rotate || true
414+
$STD journalctl --vacuum-time=10m || true
412415
fi
413416
msg_ok "Cleaned"
414417
}

0 commit comments

Comments
 (0)