adaptai / platform /dbops /tools /host_namespace_bootstrap.sh
ADAPT-Chase's picture
Add files using upload-large-folder tool
503b0e9 verified
raw
history blame
1.38 kB
#!/usr/bin/env bash
set -euo pipefail
# Idempotently set up host-namespaced data/logs under dbops/b/<host_id>
# and symlink stable paths `data` and `logs` to them.
DBOPS_ROOT=${DBOPS_ROOT:-/data/adaptai/platform/dbops}
HOST_ID=${HOST_ID:-$(hostname -s 2>/dev/null || echo host)}
echo "[hostns] DBOPS_ROOT=$DBOPS_ROOT HOST_ID=$HOST_ID"
mkdir -p "$DBOPS_ROOT/b/$HOST_ID/data" "$DBOPS_ROOT/b/$HOST_ID/logs"
# Move current dirs into host namespace if not symlinks
backup_sfx=$(date +%s)
if [ ! -L "$DBOPS_ROOT/data" ] && [ -d "$DBOPS_ROOT/data" ]; then
echo "[hostns] migrating data/ -> b/$HOST_ID/data"
rsync -a "$DBOPS_ROOT/data/" "$DBOPS_ROOT/b/$HOST_ID/data/" || true
mv "$DBOPS_ROOT/data" "$DBOPS_ROOT/data.bak.$backup_sfx" || true
fi
if [ ! -L "$DBOPS_ROOT/logs" ] && [ -d "$DBOPS_ROOT/logs" ]; then
echo "[hostns] migrating logs/ -> b/$HOST_ID/logs"
rsync -a "$DBOPS_ROOT/logs/" "$DBOPS_ROOT/b/$HOST_ID/logs/" || true
mv "$DBOPS_ROOT/logs" "$DBOPS_ROOT/logs.bak.$backup_sfx" || true
fi
ln -sfn "$DBOPS_ROOT/b/$HOST_ID/data" "$DBOPS_ROOT/data"
ln -sfn "$DBOPS_ROOT/b/$HOST_ID/logs" "$DBOPS_ROOT/logs"
# Ensure common service subdirs exist
for svc in dragonfly janusgraph qdrant redis scylla; do
mkdir -p "$DBOPS_ROOT/data/$svc"
mkdir -p "$DBOPS_ROOT/logs/$svc"
done
echo "[hostns] complete:"
ls -l "$DBOPS_ROOT" | egrep ' data$| logs$' || true
exit 0