From 49902b4a668c6d64f7413970a371afddfe042f8c Mon Sep 17 00:00:00 2001 From: eriknordmark Date: Thu, 11 Jan 2024 16:38:44 +0100 Subject: [PATCH] onboot.sh: Diskspace recovery if less than 4Gbyte free. Works with ZFS Signed-off-by: eriknordmark --- pkg/pillar/scripts/onboot.sh | 44 ++++++++++-------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/pkg/pillar/scripts/onboot.sh b/pkg/pillar/scripts/onboot.sh index a2b0e304b9a..6544b68b240 100755 --- a/pkg/pillar/scripts/onboot.sh +++ b/pkg/pillar/scripts/onboot.sh @@ -19,7 +19,6 @@ FIRSTBOOT= TPM_DEVICE_PATH="/dev/tpmrm0" SECURITYFSPATH=/sys/kernel/security PATH=$BINDIR:$PATH -DISKSPACE_RECOVERY_LIMIT=70 # XXX remove MIN_DISKSPACE=4096 # MBytes echo "$(date -Ins -u) Starting onboot.sh" @@ -157,54 +156,35 @@ free_space() { # /persist/vault/downloader # /persist/vault/verifier # /persist/agentdbug -# XXX remove -diskspace_used=$(percent_used persist) -echo "Used percentage of /persist: $diskspace_used" -if [ "$diskspace_used" -ge "$DISKSPACE_RECOVERY_LIMIT" ] -then - echo "Used percentage of /persist is $diskspace_used more than the limit $DISKSPACE_RECOVERY_LIMIT" - for DIR in log pubsub-large netdump newlog/keepSentQueue newlog/failedUpload newlog/appUpload newlog/devUpload containerd-system-root vault/containerd vault/downloader vault/verifier agentdebug - do - dir_del=$PERSISTDIR/$DIR - # XXX disable for test purposes - # rm -rf "${dir_del:?}/"* - echo "XXX rm -rf "${dir_del:?}/"*" - diskspace_used=$(percent_used persist) - echo "Used percentage of /persist is $diskspace_used after clearing $dir_del" - if [ "$diskspace_used" -le "$DISKSPACE_RECOVERY_LIMIT" ] - then - break - fi - done - diskspace_used=$(percent_used persist) - echo "Used percentage of /persist after recovery: $diskspace_used" -fi diskspace_free=$(free_space persist) -echo "Free space in /persist: $diskspace_free MBytes" +echo "Free space in /persist: $diskspace_free MBytes" | tee /dev/console if [ "$diskspace_free" -lt "$MIN_DISKSPACE" ] then - echo "Free space in /persist is only $diskspace_free hence below the limit $MIN_DISKSPACE MBytes" + echo "Free space in /persist is only $diskspace_free hence below the limit $MIN_DISKSPACE MBytes" | tee /dev/console for DIR in log pubsub-large netdump newlog/keepSentQueue newlog/failedUpload newlog/appUpload newlog/devUpload containerd-system-root vault/containerd vault/downloader vault/verifier agentdebug do dir_del=$PERSISTDIR/$DIR rm -rf "${dir_del:?}/"* diskspace_free=$(free_space persist) - echo "Free space in /persist after clearing $dir_del: $diskspace_free MBytes" + echo "Free space in /persist after clearing $dir_del: $diskspace_free MBytes" | tee /dev/console + # Need to wait for ZFS to free space + # Two separate sleeps to log long delays + sleep 5 + diskspace_free=$(free_space persist) + echo "Free space in /persist after clearing $dir_del and 5s sleep: $diskspace_free MBytes" | tee /dev/console + sleep 55 + diskspace_free=$(free_space persist) + echo "Free space in /persist after clearing $dir_del and 60s sleep: $diskspace_free MBytes" | tee /dev/console if [ "$diskspace_free" -ge "$MIN_DISKSPACE" ] then break fi done diskspace_free=$(free_space persist) - echo "Free space in /persist after recovery: $diskspace_free MBytes" + echo "Free space in /persist after recovery: $diskspace_free MBytes" | tee /dev/console fi -# XXX dump sizes by appending to /persist/log/sizes -echo "$(date -Ins -u) onboot.sh sizes" >>/persist/log/sizes -du -m /persist >>/persist/log/sizes -echo "$(date -Ins -u) onboot.sh sizes done" >>/persist/log/sizes - # Run upgradeconverter mkdir -p /persist/ingested/ echo "$(date -Ins -u) onboot.sh: Starting upgradeconverter (pre-vault)"