fix: report installer compose failures
This commit is contained in:
+29
-5
@@ -26,7 +26,12 @@ progress() {
|
|||||||
printf '[%d/%d] %s\n' "$STEP" "$TOTAL_STEPS" "$1" >>"$INSTALL_LOG"
|
printf '[%d/%d] %s\n' "$STEP" "$TOTAL_STEPS" "$1" >>"$INSTALL_LOG"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
run_logged() { "$@" >>"$INSTALL_LOG" 2>&1; }
|
run_logged() {
|
||||||
|
if "$@" >>"$INSTALL_LOG" 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
usage() { sed -n '1,20p' "$0"; }
|
usage() { sed -n '1,20p' "$0"; }
|
||||||
while (($#)); do
|
while (($#)); do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@@ -78,6 +83,7 @@ else
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
chmod 600 "$PG_PASSWORD_FILE"
|
chmod 600 "$PG_PASSWORD_FILE"
|
||||||
|
rm -f "$INSTALL_DIR/secrets/postgres-password"
|
||||||
TEMPLATE_DIR="$INSTALL_DIR/bootstrap"
|
TEMPLATE_DIR="$INSTALL_DIR/bootstrap"
|
||||||
mkdir -p "$TEMPLATE_DIR"
|
mkdir -p "$TEMPLATE_DIR"
|
||||||
template_file() {
|
template_file() {
|
||||||
@@ -182,11 +188,18 @@ for placeholder, value in values.items():
|
|||||||
content = content.replace(placeholder, value)
|
content = content.replace(placeholder, value)
|
||||||
output.write_text(content)
|
output.write_text(content)
|
||||||
PY
|
PY
|
||||||
|
rm -f "$INSTALL_DIR/compose.yaml" "$INSTALL_DIR/Dockerfile.bootstrap"
|
||||||
cp "$COMPOSE_TEMPLATE" "$DOCKERFILE_TEMPLATE" "$INSTALL_DIR/"
|
cp "$COMPOSE_TEMPLATE" "$DOCKERFILE_TEMPLATE" "$INSTALL_DIR/"
|
||||||
progress '下载 bootstrap runtime'
|
progress '下载 bootstrap runtime'
|
||||||
run_logged "${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" pull app || die 'bootstrap runtime 下载失败;请确认能访问 git.keeper.work Container Registry'
|
if ! run_logged "${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" pull app; then
|
||||||
|
die 'bootstrap runtime 下载失败;请确认能访问 git.keeper.work Container Registry'
|
||||||
|
fi
|
||||||
progress '启动 PostgreSQL'
|
progress '启动 PostgreSQL'
|
||||||
if [[ $PG_HOST == postgres ]]; then run_logged "${COMPOSE[@]}" --profile local-db --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" up -d postgres || die 'PostgreSQL 启动失败'; fi
|
if [[ $PG_HOST == postgres ]]; then
|
||||||
|
if ! run_logged "${COMPOSE[@]}" --profile local-db --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" up -d postgres; then
|
||||||
|
die 'PostgreSQL 启动失败'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
if [[ $PG_HOST == postgres ]]; then
|
if [[ $PG_HOST == postgres ]]; then
|
||||||
ready=0
|
ready=0
|
||||||
for elapsed in $(seq 0 118 2); do
|
for elapsed in $(seq 0 118 2); do
|
||||||
@@ -202,9 +215,20 @@ if [[ $PG_HOST == postgres ]]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
progress '初始化数据库结构'
|
progress '初始化数据库结构'
|
||||||
if (( EXISTING_DB )); then export XYMEDIA_EXTERNAL_MIGRATION_CONFIRM=YES; run_logged "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" run --rm --no-deps app-migrate migrate --config /app/config.yaml || die '已有数据库迁移失败'; else run_logged "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" run --rm --no-deps app-migrate migrate --new --config /app/config.yaml || die '数据库初始化失败'; fi
|
if (( EXISTING_DB )); then
|
||||||
|
export XYMEDIA_EXTERNAL_MIGRATION_CONFIRM=YES
|
||||||
|
if ! run_logged "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" run --rm --no-deps app-migrate migrate --config /app/config.yaml; then
|
||||||
|
die '已有数据库迁移失败'
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
if ! run_logged "${COMPOSE[@]}" --profile migration --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" run --rm --no-deps app-migrate migrate --new --config /app/config.yaml; then
|
||||||
|
die '数据库初始化失败'
|
||||||
|
fi
|
||||||
|
fi
|
||||||
progress '启动 XyMediaVault 服务'
|
progress '启动 XyMediaVault 服务'
|
||||||
run_logged "${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" up -d app || die 'XyMediaVault 启动失败'
|
if ! run_logged "${COMPOSE[@]}" --project-directory "$INSTALL_DIR" --env-file "$INSTALL_DIR/.env" -f "$INSTALL_DIR/compose.yaml" up -d app; then
|
||||||
|
die 'XyMediaVault 启动失败'
|
||||||
|
fi
|
||||||
for elapsed in $(seq 0 118 2); do
|
for elapsed in $(seq 0 118 2); do
|
||||||
curl --fail --silent "http://127.0.0.1:$API_PORT/api/health" >/dev/null && { cp "$INSTALL_LOG" "$INSTALL_DIR/install.log" 2>/dev/null || true; printf '\033[2K\r[%d/%d] 安装完成:XyMediaVault 已就绪\n' "$TOTAL_STEPS" "$TOTAL_STEPS"; printf '管理地址:http://127.0.0.1:%s\n安装日志:%s\n' "$API_PORT" "$INSTALL_LOG"; exit 0; }
|
curl --fail --silent "http://127.0.0.1:$API_PORT/api/health" >/dev/null && { cp "$INSTALL_LOG" "$INSTALL_DIR/install.log" 2>/dev/null || true; printf '\033[2K\r[%d/%d] 安装完成:XyMediaVault 已就绪\n' "$TOTAL_STEPS" "$TOTAL_STEPS"; printf '管理地址:http://127.0.0.1:%s\n安装日志:%s\n' "$API_PORT" "$INSTALL_LOG"; exit 0; }
|
||||||
printf '\033[2K\r[%d/%d] 等待 XyMediaVault 健康检查(%s 秒)' "$STEP" "$TOTAL_STEPS" "$elapsed"
|
printf '\033[2K\r[%d/%d] 等待 XyMediaVault 健康检查(%s 秒)' "$STEP" "$TOTAL_STEPS" "$elapsed"
|
||||||
|
|||||||
Reference in New Issue
Block a user