fix: preserve migrated storage guards during deployment

This commit is contained in:
hectorzhao
2026-08-31 23:01:35 +08:00
parent fd373d9708
commit 9a15d28da5
6 changed files with 78 additions and 1 deletions
+32
View File
@@ -0,0 +1,32 @@
#!/usr/bin/env bash
set -euo pipefail
fail() { echo "CMPP data storage unavailable: $*" >&2; exit 1; }
expected_uuid=$(cat /etc/cmpp-platform/data-disk.uuid) || fail "expected UUID configuration is missing"
[[ "$expected_uuid" =~ ^[a-f0-9-]{36}$ ]] || fail "invalid expected UUID"
mountpoint -q /data || fail "/data is not mounted"
[[ "$(findmnt -rn -M /data -o UUID)" == "$expected_uuid" ]] || fail "/data UUID mismatch"
[[ "$(cat /data/.cmpp-data-disk.uuid)" == "$expected_uuid" ]] || fail "data marker mismatch"
case ",$(findmnt -rn -M /data -o OPTIONS)," in *,rw,*) ;; *) fail "/data is read-only";; esac
check_one() {
local role="$1" source target
case "$role" in
postgresql) source=/data/postgresql; target=/var/lib/pgsql ;;
redis) source=/data/redis; target=/var/lib/redis ;;
minio) source=/data/minio; target=/var/lib/minio ;;
*) fail "unknown service $role" ;;
esac
mountpoint -q "$target" || fail "$target is not a mount point"
[[ "$(findmnt -rn -M "$target" -o UUID)" == "$expected_uuid" ]] || fail "$target UUID mismatch"
[[ "$(stat -Lc '%d:%i' "$source")" == "$(stat -Lc '%d:%i' "$target")" ]] || fail "$target does not map to $source"
case ",$(findmnt -rn -M "$target" -o OPTIONS)," in *,rw,*) ;; *) fail "$target is read-only";; esac
case "$role" in
postgresql) [[ -s "$target/data/PG_VERSION" && -d "$target/data/base" ]] || fail "existing PostgreSQL cluster is missing" ;;
redis) [[ -s "$target/dump.rdb" ]] || fail "existing Redis RDB is missing" ;;
minio) [[ -s "$target/.minio.sys/format.json" ]] || fail "existing MinIO format is missing" ;;
esac
echo "CMPP storage OK: $role $target -> $source UUID=$expected_uuid"
}
case "${1:-all}" in
all) check_one postgresql; check_one redis; check_one minio ;;
*) check_one "$1" ;;
esac
+9
View File
@@ -1,6 +1,15 @@
#!/usr/bin/env bash
set -Eeuo pipefail
# Existing data-disk installations must fail before any initialization or release writes.
if [[ -e /etc/cmpp-platform/data-disk.uuid || -e /etc/systemd/system/postgresql.service.d/50-cmpp-data-disk.conf ]]; then
if [[ ! -x /usr/local/sbin/cmpp-data-storage-check ]]; then
echo "Missing CMPP data-disk guard; refusing to continue." >&2
exit 1
fi
/usr/local/sbin/cmpp-data-storage-check all
fi
APP_DIR="${APP_DIR:-/opt/cmpp-platform}"
REPO_URL="${REPO_URL:-http://175.27.255.91:3000/hectorzhao/lislgosms.git}"
BRANCH="${BRANCH:-main}"
+9
View File
@@ -1,6 +1,15 @@
#!/usr/bin/env bash
set -Eeuo pipefail
# Existing data-disk installations must fail before any initialization or release writes.
if [[ -e /etc/cmpp-platform/data-disk.uuid || -e /etc/systemd/system/postgresql.service.d/50-cmpp-data-disk.conf ]]; then
if [[ ! -x /usr/local/sbin/cmpp-data-storage-check ]]; then
echo "Missing CMPP data-disk guard; refusing to continue." >&2
exit 1
fi
/usr/local/sbin/cmpp-data-storage-check all
fi
APP_DIR="${APP_DIR:-/opt/cmpp-platform}"
ENV_FILE="${ENV_FILE:-/etc/cmpp-platform/cmpp-platform.env}"
ADMIN_CREDENTIAL_FILE="${ADMIN_CREDENTIAL_FILE:-/root/cmpp-platform-admin.txt}"
+20 -1
View File
@@ -6,6 +6,25 @@ const bootstrap = readFileSync(resolve(import.meta.dirname, 'production-bootstra
const apiMain = readFileSync(resolve(import.meta.dirname, '../../api/src/main.ts'), 'utf8');
const apiTimeouts = readFileSync(resolve(import.meta.dirname, '../../api/src/http-server-timeouts.ts'), 'utf8');
const workerMain = readFileSync(resolve(import.meta.dirname, '../../api/src/send-worker.ts'), 'utf8');
const storageCheck = readFileSync(resolve(import.meta.dirname, 'check-data-storage.sh'), 'utf8');
for (const [name, script] of [['deploy', deploy], ['bootstrap', bootstrap]]) {
const guard = script.indexOf('/usr/local/sbin/cmpp-data-storage-check all');
const initialization = script.indexOf('APP_DIR=');
if (guard < 0 || initialization < 0 || guard > initialization) {
throw new Error(`${name} must verify migrated storage before initialization or release writes`);
}
for (const marker of ['data-disk.uuid', '50-cmpp-data-disk.conf', '[[ ! -x /usr/local/sbin/cmpp-data-storage-check ]]', 'refusing to continue.']) {
if (!script.includes(marker)) throw new Error(`${name} is missing the data-disk fail-closed guard: ${marker}`);
}
}
for (const marker of [
'mountpoint -q /data', 'findmnt -rn -M /data -o UUID', '/data/.cmpp-data-disk.uuid',
'mountpoint -q "$target"', 'findmnt -rn -M "$target" -o UUID', "stat -Lc '%d:%i'",
'findmnt -rn -M "$target" -o OPTIONS', '/data/postgresql', '/data/redis', '/data/minio',
'PG_VERSION', 'dump.rdb', '.minio.sys/format.json',
]) {
if (!storageCheck.includes(marker)) throw new Error(`data storage guard is missing: ${marker}`);
}
const required = [
'compression_config=/etc/nginx/conf.d/cmpp-compression.conf',
': >"$compression_config"',
@@ -65,4 +84,4 @@ if (gatewayRestart < 0 || apiRestart < gatewayRestart || workerRestart < apiRest
throw new Error('production deploy must restart Gateway before API and the send worker so API startup restores active channels');
}
console.log('Production deployment verified: Nginx/API guards and the split durable send worker contract are present.');
console.log('Production deployment verified: migrated storage fail-closed guards, Nginx/API guards and the split durable send worker contract are present.');