Skip to content

Commit

Permalink
Clean up old CAR files at 10% chance (#457)
Browse files Browse the repository at this point in the history
* Clean up old CAR files at 10% chance

* carall too

* fix brackets
  • Loading branch information
Diego Rodríguez Baquero authored Jul 14, 2023
1 parent dec83f6 commit 411ab92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions container/shim/src/utils/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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.`
);
Expand Down
7 changes: 7 additions & 0 deletions container/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 411ab92

Please sign in to comment.