From 411ab92bac8d5894b4d44973a4909404c2bbeb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Baquero?= Date: Fri, 14 Jul 2023 13:59:52 -0500 Subject: [PATCH] Clean up old CAR files at 10% chance (#457) * Clean up old CAR files at 10% chance * carall too * fix brackets --- container/shim/src/utils/system.js | 6 +++--- container/start.sh | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/container/shim/src/utils/system.js b/container/shim/src/utils/system.js index 858de786..0b17ee0b 100644 --- a/container/shim/src/utils/system.js +++ b/container/shim/src/utils/system.js @@ -4,7 +4,7 @@ import { debug as Debug } from "./logging.js"; import { promisify } from "node:util"; import { exec as CpExec } from "node:child_process"; import prettyBytes from "pretty-bytes"; -import { SPEEDTEST_SERVER_CONFIG } from "../config.js"; +import { NETWORK, SPEEDTEST_SERVER_CONFIG } from "../config.js"; const exec = promisify(CpExec); @@ -48,8 +48,8 @@ export async function getDiskStats() { const usedDiskMB = valuesMB[2]; const availableDiskMB = valuesMB[3]; debug(`Disk Total: ${totalDiskMB / 1000} GB Used: ${usedDiskMB / 1000} GB Available: ${availableDiskMB / 1000} GB`); - if (availableDiskMB <= 50 * 1000) { - // 50 GB + if (availableDiskMB <= (NETWORK === "test" ? 10 : 50) * 1000) { + // 50 GB for mainnet, 10 GB for testnet debug( `WARNING: Full disk. Cache will be rotated and affect performance severely. Please consider upgrading your L1 node disk space.` ); diff --git a/container/start.sh b/container/start.sh index 60684dfd..d01290b1 100755 --- a/container/start.sh +++ b/container/start.sh @@ -25,6 +25,13 @@ echo "$(date -u) [container] Disk: $(df -h /usr/src/app/shared | awk '(NR>1)')" mkdir -p /usr/src/app/shared/ssl mkdir -p /usr/src/app/shared/nginx_log +# Clean up old cached CAR files with 10% chance and if not already cleaned up +if [ "$RANDOM" -lt 3277 ] && [ ! -f "/usr/src/app/shared/cleaned_cache" ]; then + echo "$(date -u) [container] Cleaning up old cached CAR files" + grep -rl '/usr/src/app/shared/nginx_cache' -e 'carentity' -e 'carall' | xargs rm -f + touch /usr/src/app/shared/cleaned_cache +fi + L1_CONF_FILE=/etc/nginx/conf.d/L1.conf # If we have a cert, start nginx with TLS, else without (but always start the shim)