fix: verify MindSpace service replacement
Memind CI / Test, build, and release guards (pull_request) Successful in 2m26s

This commit is contained in:
john
2026-07-21 18:55:23 +08:00
parent fe4b8c0da9
commit 4e6db07123
2 changed files with 67 additions and 5 deletions
+23 -5
View File
@@ -203,6 +203,10 @@ say() {
printf '\n[remote %s] %s\n' "$(date +%H:%M:%S)" "$*"
}
service_is_running() {
launchctl print "${LAUNCHD_GUI}/${SERVICE_LABEL}" 2>/dev/null | grep -q 'state = running'
}
rollback() {
set +e
say "rollback: restoring previous state"
@@ -314,6 +318,16 @@ EOF
say "切换 MindSpace service live 目录"
launchctl bootout "${LAUNCHD_GUI}/${SERVICE_LABEL}" >/dev/null 2>&1 || true
for _ in $(seq 1 60); do
if ! lsof -nP -iTCP:8082 -sTCP:LISTEN >/dev/null 2>&1; then
break
fi
sleep 1
done
if lsof -nP -iTCP:8082 -sTCP:LISTEN >/dev/null 2>&1; then
echo "旧 MindSpace service 未在超时内退出,拒绝切换 runtime" >&2
exit 1
fi
rm -rf "${OLD_APP_ARCHIVE}"
if [[ -d "${APP_DIR}" ]]; then
mv "${APP_DIR}" "${OLD_APP_ARCHIVE}"
@@ -335,19 +349,20 @@ fi
say "启动 MindSpace service"
mkdir -p "${APP_DIR}/data/mindspace" "${APP_DIR}/users"
launchctl bootstrap "${LAUNCHD_GUI}" "${SERVICE_PLIST}" >/dev/null 2>&1 || true
launchctl enable "${LAUNCHD_GUI}/${SERVICE_LABEL}" >/dev/null 2>&1 || true
launchctl kickstart -k "${LAUNCHD_GUI}/${SERVICE_LABEL}" >/dev/null 2>&1 || true
launchctl bootstrap "${LAUNCHD_GUI}" "${SERVICE_PLIST}" >/dev/null
SERVICE_STARTED=1
launchctl enable "${LAUNCHD_GUI}/${SERVICE_LABEL}" >/dev/null
launchctl kickstart -k "${LAUNCHD_GUI}/${SERVICE_LABEL}" >/dev/null
for _ in $(seq 1 30); do
code="$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8082/health || true)"
if [[ "${code}" == "200" ]]; then
if [[ "${code}" == "200" ]] && service_is_running; then
break
fi
sleep 1
done
[[ "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8082/health || true)" == "200" ]]
service_is_running
[[ "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8082/mindspace/v1/contract || true)" == "200" ]]
set_env() {
@@ -395,6 +410,9 @@ for _ in $(seq 1 30); do
sleep 1
done
[[ "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8081/api/status || true)" == "200" ]]
sleep 3
[[ "$(curl -s -o /dev/null -w '%{http_code}' http://127.0.0.1:8082/health || true)" == "200" ]]
service_is_running
trap - ERR
@@ -403,7 +421,7 @@ printf 'release_id=%s\n' "${RELEASE_ID}"
printf 'service_root=%s\n' "${APP_DIR}"
printf 'service_backup=%s\n' "${APP_BACKUP}"
printf 'env_backup=%s\n' "${ENV_BACKUP}"
printf 'service_health=%s\n' "$(curl -s http://127.0.0.1:8082/health)"
printf 'service_health=%s\n' "$(curl -fsS http://127.0.0.1:8082/health)"
REMOTE
say "发布完成"