Skip to content

Commit 2229569

Browse files
committed
Check for free space
1 parent 26f10d7 commit 2229569

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

migrate.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,29 @@ assert_running_as_root() {
295295
fi
296296
}
297297

298+
assert_enough_disk_space() {
299+
local SANDSTORM_CONF="${SANDSTORM_CONF:-/opt/sandstorm/sandstorm.conf}"
300+
local SANDSTORM_DIR
301+
SANDSTORM_DIR=$(grep '^SANDSTORM_HOME=' "$SANDSTORM_CONF" | cut -d= -f2)
302+
SANDSTORM_DIR="${SANDSTORM_DIR:-/opt/sandstorm}"
303+
304+
# df -k reports available space in 1KB blocks; convert to GB for the comparison.
305+
local AVAILABLE_KB
306+
AVAILABLE_KB=$(df -k "$SANDSTORM_DIR" | awk 'NR==2 {print $4}')
307+
308+
local REQUIRED_KB=$((1024 * 1024)) # 1 GB in KB
309+
310+
if [ "$AVAILABLE_KB" -lt "$REQUIRED_KB" ]; then
311+
local AVAILABLE_MB=$(( AVAILABLE_KB / 1024 ))
312+
fail "E_INSUFFICIENT_DISK_SPACE" \
313+
"Insufficient disk space on the Sandstorm volume ($SANDSTORM_DIR).
314+
Required: 1024 MB
315+
Available: ${AVAILABLE_MB} MB
316+
317+
Please free up disk space before running this migration."
318+
fi
319+
}
320+
298321
assert_user_has_backed_up() {
299322
echo ""
300323
echo "*** IMPORTANT: DATABASE UPGRADE WARNING ***"
@@ -466,6 +489,7 @@ assert_on_terminal
466489
assert_dependencies
467490
assert_sandstorm_installed
468491
assert_running_as_root
492+
assert_enough_disk_space
469493
assert_user_has_backed_up
470494
assert_valid_bundle_file
471495
download_latest_bundle_if_needed

0 commit comments

Comments
 (0)