Files
getDomain/domain-api/deploy/multi-region/check_mainland_worker.sh
Your Name bd6bcb240f debug
2026-04-17 16:17:19 +08:00

71 lines
1.9 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
ENV_FILE="${1:-/etc/default/domaincheck-worker}"
WORKER_SERVICE="${WORKER_SERVICE:-domaincheck-worker}"
PYTHON_BIN="${PYTHON_BIN:-python3}"
echo "[1/4] environment file"
if [ ! -f "$ENV_FILE" ]; then
echo "missing env file: $ENV_FILE"
exit 1
fi
echo "env file: $ENV_FILE"
echo
echo "[2/4] key env summary"
"${PYTHON_BIN}" - <<'PY' "$ENV_FILE"
import json
import sys
from pathlib import Path
env_path = Path(sys.argv[1])
values = {}
for line in env_path.read_text(encoding="utf-8").splitlines():
text = line.strip()
if not text or text.startswith("#") or "=" not in text:
continue
key, value = text.split("=", 1)
values[key.strip()] = value.strip()
required = {
"NODE_CODE": values.get("NODE_CODE", ""),
"NODE_REGION": values.get("NODE_REGION", ""),
"NODE_ROLE": values.get("NODE_ROLE", ""),
"DB_HOST": values.get("DB_HOST", ""),
"DB_PORT": values.get("DB_PORT", ""),
"REDIS_HOST": values.get("REDIS_HOST", ""),
"REDIS_PORT": values.get("REDIS_PORT", ""),
"SYNC_TARGET_API_BASE_URL": values.get("SYNC_TARGET_API_BASE_URL", ""),
}
print(json.dumps(required, ensure_ascii=False, indent=2))
errors = []
if required["NODE_REGION"] != "mainland":
errors.append("NODE_REGION 必须为 mainland")
if required["NODE_ROLE"] != "worker":
errors.append("NODE_ROLE 必须为 worker")
if not required["NODE_CODE"]:
errors.append("NODE_CODE 不能为空")
if not required["DB_HOST"]:
errors.append("DB_HOST 不能为空")
if not required["REDIS_HOST"]:
errors.append("REDIS_HOST 不能为空")
if errors:
print()
print("env validation failed:")
for item in errors:
print(f"- {item}")
sys.exit(1)
PY
echo
echo "[3/4] systemd status"
systemctl is-enabled "$WORKER_SERVICE" || true
systemctl is-active "$WORKER_SERVICE"
echo
echo "[4/4] worker service detail"
systemctl status "$WORKER_SERVICE" --no-pager -l | sed -n '1,30p'