From 466e35b5d194f80b6592346b7eb3d287a919923a Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Fri, 24 Mar 2023 16:53:56 +0100 Subject: [PATCH] add gc --- hcl/gc.sh | 26 ++++++++++++++++++++++++++ main.go | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 hcl/gc.sh diff --git a/hcl/gc.sh b/hcl/gc.sh new file mode 100644 index 0000000..2396464 --- /dev/null +++ b/hcl/gc.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euxo pipefail + +# prepare workspace just in case +mkdir -p /nix/var/nix/gcroots/albatros +cd /nix/var/nix/gcroots/albatros + +# remove any symlink that is older than 7 days +NOW=$(date +%s) +#EXPIRE=$((60*60*24*7)) # 7 days in seconds +EXPIRE=1700 # 7 days in seconds + +for f in $(ls); do + CR=$(stat $f -c %W) + DIFF=$((NOW-CR)) + if [[ $DIFF -gt $EXPIRE ]]; then + echo "deleting $f" + rm -f $f + else + echo "keeping $f"; + fi +done + +# we don't want to slow down the build too much, so +# we limit to 1GB of deletion +nix store gc --verbose --max 1G diff --git a/main.go b/main.go index a881540..405c02f 100644 --- a/main.go +++ b/main.go @@ -404,7 +404,7 @@ func initConsul() { func main() { var err error - // init components + // init components. initConfig() initNomad() initConsul()