fix free space calculation and make it based on absolute values instead of pcts
This commit is contained in:
parent
3ee3916b29
commit
3ddc0c7f7a
1 changed files with 24 additions and 19 deletions
|
@ -10,6 +10,7 @@
|
||||||
# - Create a new /data dir if necessary and set the correct ownership on it
|
# - Create a new /data dir if necessary and set the correct ownership on it
|
||||||
# - Create a new /browsers dir if necessary and set the correct ownership on it
|
# - Create a new /browsers dir if necessary and set the correct ownership on it
|
||||||
# - Check whether we're running inside QEMU emulation and show a warning if so.
|
# - Check whether we're running inside QEMU emulation and show a warning if so.
|
||||||
|
# - Check that enough free space is available on / and /data
|
||||||
# - Drop down to archivebox user permisisons and execute passed CMD command.
|
# - Drop down to archivebox user permisisons and execute passed CMD command.
|
||||||
|
|
||||||
# Bash Environment Setup
|
# Bash Environment Setup
|
||||||
|
@ -84,7 +85,7 @@ chown $PUID:$PGID "$DATA_DIR"
|
||||||
chown $PUID:$PGID "$DATA_DIR"/*
|
chown $PUID:$PGID "$DATA_DIR"/*
|
||||||
|
|
||||||
# also chown BROWSERS_DIR because otherwise 'archivebox setup' wont be able to install chrome at runtime
|
# also chown BROWSERS_DIR because otherwise 'archivebox setup' wont be able to install chrome at runtime
|
||||||
PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-/browsers}"
|
export PLAYWRIGHT_BROWSERS_PATH="${PLAYWRIGHT_BROWSERS_PATH:-/browsers}"
|
||||||
mkdir -p "$PLAYWRIGHT_BROWSERS_PATH/permissions_test_safe_to_delete"
|
mkdir -p "$PLAYWRIGHT_BROWSERS_PATH/permissions_test_safe_to_delete"
|
||||||
chown $PUID:$PGID "$PLAYWRIGHT_BROWSERS_PATH"
|
chown $PUID:$PGID "$PLAYWRIGHT_BROWSERS_PATH"
|
||||||
chown $PUID:$PGID "$PLAYWRIGHT_BROWSERS_PATH"/*
|
chown $PUID:$PGID "$PLAYWRIGHT_BROWSERS_PATH"/*
|
||||||
|
@ -99,37 +100,41 @@ if [[ "$IN_QEMU" == "True" ]]; then
|
||||||
echo -e " See here for more info: https://github.com/microsoft/playwright/issues/17395#issuecomment-1250830493\n" > /dev/stderr
|
echo -e " See here for more info: https://github.com/microsoft/playwright/issues/17395#issuecomment-1250830493\n" > /dev/stderr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check disk space free on / and /data, warn on >95% use, error on >99% use
|
# check disk space free on / and /data, warn on <500Mb free, error on <100Mb free
|
||||||
ROOT_USED_PCT="$(df --output=pcent / | tail -n 1 | xargs)"
|
export ROOT_USAGE="$(df --output=pcent,avail / | tail -n 1 | xargs)"
|
||||||
if [[ "${ROOT_USED_PCT//%/}" -ge 99 ]]; then
|
export ROOT_USED_PCT="${ROOT_USAGE%%%*}"
|
||||||
df -kh / > /dev/stderr
|
export ROOT_AVAIL_KB="$(echo "$ROOT_USAGE" | awk '{print $2}')"
|
||||||
echo -e "\n[!] Warning: Docker root filesystem is completely out of space! ($ROOT_USED_PCT used on /)" > /dev/stderr
|
if [[ "$ROOT_AVAIL_KB" -lt 100000 ]]; then
|
||||||
echo -e " you need to free up space in your Docker VM to continue:" > /dev/stderr
|
echo -e "\n[!] Warning: Docker root filesystem is completely out of space! (${ROOT_USED_PCT}% used on /)" > /dev/stderr
|
||||||
|
echo -e " you need to free up at least 100Mb in your Docker VM to continue:" > /dev/stderr
|
||||||
echo -e " \$ docker system prune\n" > /dev/stderr
|
echo -e " \$ docker system prune\n" > /dev/stderr
|
||||||
exit 3
|
|
||||||
elif [[ "${ROOT_USED_PCT//%/}" -gt 97 ]]; then
|
|
||||||
df -kh / > /dev/stderr
|
df -kh / > /dev/stderr
|
||||||
echo -e "\n[!] Warning: Docker root filesystem is running out of space! ($ROOT_USED_PCT used on /)" > /dev/stderr
|
exit 3
|
||||||
|
elif [[ "$ROOT_USED_PCT" -ge 99 ]] || [[ "$ROOT_AVAIL_KB" -lt 500000 ]]; then
|
||||||
|
echo -e "\n[!] Warning: Docker root filesystem is running out of space! (${ROOT_USED_PCT}% used on /)" > /dev/stderr
|
||||||
echo -e " you may need to free up space in your Docker VM soon:" > /dev/stderr
|
echo -e " you may need to free up space in your Docker VM soon:" > /dev/stderr
|
||||||
echo -e " \$ docker system prune\n" > /dev/stderr
|
echo -e " \$ docker system prune\n" > /dev/stderr
|
||||||
|
df -kh / > /dev/stderr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
DATA_USED_PCT="$(df --output=pcent /data | tail -n 1 | xargs)"
|
export DATA_USAGE="$(df --output=pcent,avail /data | tail -n 1 | xargs)"
|
||||||
if [[ "${DATA_USED_PCT//%/}" -ge 99 ]]; then
|
export DATA_USED_PCT="${DATA_USAGE%%%*}"
|
||||||
df -kh /data > /dev/stderr
|
export DATA_AVAIL_KB="$(echo "$DATA_USAGE" | awk '{print $2}')"
|
||||||
echo -e "\n[!] Warning: Docker data volume is completely out of space! ($DATA_USED_PCT used on /data)" > /dev/stderr
|
if [[ "$DATA_AVAIL_KB" -lt 100000 ]]; then
|
||||||
echo -e " you need to free up space on the drive holding your data directory" > /dev/stderr
|
echo -e "\n[!] Warning: Docker data volume is completely out of space! (${DATA_USED_PCT}% used on /data)" > /dev/stderr
|
||||||
|
echo -e " you need to free up at least 100Mb on the drive holding your data directory" > /dev/stderr
|
||||||
echo -e " \$ ncdu -x data\n" > /dev/stderr
|
echo -e " \$ ncdu -x data\n" > /dev/stderr
|
||||||
sleep 5
|
|
||||||
elif [[ "${DATA_USED_PCT//%/}" -gt 95 ]]; then
|
|
||||||
df -kh /data > /dev/stderr
|
df -kh /data > /dev/stderr
|
||||||
echo -e "\n[!] Warning: Docker data volume is running out of space! ($DATA_USED_PCT used on /data)" > /dev/stderr
|
sleep 5
|
||||||
|
elif [[ "$DATA_USED_PCT" -ge 99 ]] || [[ "$ROOT_AVAIL_KB" -lt 500000 ]]; then
|
||||||
|
echo -e "\n[!] Warning: Docker data volume is running out of space! (${DATA_USED_PCT}% used on /data)" > /dev/stderr
|
||||||
echo -e " you may need to free up space on the drive holding your data directory soon" > /dev/stderr
|
echo -e " you may need to free up space on the drive holding your data directory soon" > /dev/stderr
|
||||||
echo -e " \$ ncdu -x data\n" > /dev/stderr
|
echo -e " \$ ncdu -x data\n" > /dev/stderr
|
||||||
|
df -kh /data > /dev/stderr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
ARCHIVEBOX_BIN_PATH="$(which archivebox)"
|
export ARCHIVEBOX_BIN_PATH="$(which archivebox)"
|
||||||
|
|
||||||
# Drop permissions to run commands as the archivebox user
|
# Drop permissions to run commands as the archivebox user
|
||||||
if [[ "$1" == /* || "$1" == "bash" || "$1" == "sh" || "$1" == "echo" || "$1" == "cat" || "$1" == "whoami" || "$1" == "archivebox" ]]; then
|
if [[ "$1" == /* || "$1" == "bash" || "$1" == "sh" || "$1" == "echo" || "$1" == "cat" || "$1" == "whoami" || "$1" == "archivebox" ]]; then
|
||||||
|
|
Loading…
Reference in a new issue