feat(mpc-system): 添加 debug 命令用于故障排查
新增 debug 命令,显示以下信息: - 环境变量配置状态 - PostgreSQL 连接测试(使用 mpc.env 中的密码) - Redis 连接测试 - RabbitMQ 状态检查 - 端口监听状态(5432, 6379, 5672, 50051, 50052, 8080) - 各服务最近 10 条日志 - 手动测试命令提示 使用方法: sudo ./scripts/deploy.sh debug 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
0604255ba8
commit
959fc3910c
|
|
@ -542,6 +542,97 @@ reconfigure() {
|
||||||
log_info "Restart services with: $0 restart"
|
log_info "Restart services with: $0 restart"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ============================================
|
||||||
|
# Debug Command (troubleshooting)
|
||||||
|
# ============================================
|
||||||
|
debug() {
|
||||||
|
echo ""
|
||||||
|
echo "============================================"
|
||||||
|
echo "MPC-System Debug Information"
|
||||||
|
echo "============================================"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
# Load environment variables
|
||||||
|
if [ -f "$CONFIG_DIR/mpc.env" ]; then
|
||||||
|
source "$CONFIG_DIR/mpc.env"
|
||||||
|
log_info "Loaded environment from $CONFIG_DIR/mpc.env"
|
||||||
|
else
|
||||||
|
log_error "Environment file not found: $CONFIG_DIR/mpc.env"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Environment Variables ==="
|
||||||
|
echo "MPC_DATABASE_HOST: ${MPC_DATABASE_HOST:-NOT SET}"
|
||||||
|
echo "MPC_DATABASE_PORT: ${MPC_DATABASE_PORT:-NOT SET}"
|
||||||
|
echo "MPC_DATABASE_USER: ${MPC_DATABASE_USER:-NOT SET}"
|
||||||
|
echo "MPC_DATABASE_PASSWORD: ${MPC_DATABASE_PASSWORD:+SET (hidden)}"
|
||||||
|
echo "MPC_DATABASE_DBNAME: ${MPC_DATABASE_DBNAME:-NOT SET}"
|
||||||
|
echo "SESSION_COORDINATOR_ADDR: ${SESSION_COORDINATOR_ADDR:-NOT SET}"
|
||||||
|
echo "MESSAGE_ROUTER_ADDR: ${MESSAGE_ROUTER_ADDR:-NOT SET}"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== PostgreSQL Connection Test ==="
|
||||||
|
local DB_USER="${MPC_DATABASE_USER:-mpc_user}"
|
||||||
|
local DB_PASS="${MPC_DATABASE_PASSWORD:-}"
|
||||||
|
local DB_NAME="${MPC_DATABASE_DBNAME:-mpc_system}"
|
||||||
|
local DB_HOST="${MPC_DATABASE_HOST:-localhost}"
|
||||||
|
|
||||||
|
# Test PostgreSQL connection with password
|
||||||
|
echo "Testing connection to PostgreSQL..."
|
||||||
|
if PGPASSWORD="$DB_PASS" psql -h 127.0.0.1 -U "$DB_USER" -d "$DB_NAME" -c "SELECT 1;" > /dev/null 2>&1; then
|
||||||
|
echo " PostgreSQL connection: ${GREEN}OK${NC}"
|
||||||
|
else
|
||||||
|
echo " PostgreSQL connection: ${RED}FAILED${NC}"
|
||||||
|
echo ""
|
||||||
|
echo " Trying with verbose output:"
|
||||||
|
PGPASSWORD="$DB_PASS" psql -h 127.0.0.1 -U "$DB_USER" -d "$DB_NAME" -c "SELECT 1;" 2>&1 || true
|
||||||
|
echo ""
|
||||||
|
echo " Check pg_hba.conf authentication method:"
|
||||||
|
cat /etc/postgresql/*/main/pg_hba.conf 2>/dev/null | grep -v "^#" | grep -v "^$" | head -10
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== Redis Connection Test ==="
|
||||||
|
if redis-cli ping > /dev/null 2>&1; then
|
||||||
|
echo " Redis connection: ${GREEN}OK${NC}"
|
||||||
|
else
|
||||||
|
echo " Redis connection: ${RED}FAILED${NC}"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== RabbitMQ Connection Test ==="
|
||||||
|
if rabbitmqctl status > /dev/null 2>&1; then
|
||||||
|
echo " RabbitMQ status: ${GREEN}OK${NC}"
|
||||||
|
else
|
||||||
|
echo " RabbitMQ status: ${RED}FAILED${NC}"
|
||||||
|
fi
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== Port Listening Status ==="
|
||||||
|
echo " PostgreSQL (5432): $(ss -tlnp | grep ':5432' > /dev/null && echo 'LISTENING' || echo 'NOT LISTENING')"
|
||||||
|
echo " Redis (6379): $(ss -tlnp | grep ':6379' > /dev/null && echo 'LISTENING' || echo 'NOT LISTENING')"
|
||||||
|
echo " RabbitMQ (5672): $(ss -tlnp | grep ':5672' > /dev/null && echo 'LISTENING' || echo 'NOT LISTENING')"
|
||||||
|
echo " Session Coordinator gRPC (50051): $(ss -tlnp | grep ':50051' > /dev/null && echo 'LISTENING' || echo 'NOT LISTENING')"
|
||||||
|
echo " Message Router gRPC (50052): $(ss -tlnp | grep ':50052' > /dev/null && echo 'LISTENING' || echo 'NOT LISTENING')"
|
||||||
|
echo " Account Service HTTP (8080): $(ss -tlnp | grep ':8080' > /dev/null && echo 'LISTENING' || echo 'NOT LISTENING')"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== Service Error Logs (last 10 lines) ==="
|
||||||
|
for service in mpc-session-coordinator mpc-message-router mpc-server-party-1 mpc-account; do
|
||||||
|
echo ""
|
||||||
|
echo "--- $service ---"
|
||||||
|
journalctl -u "$service" --no-pager -n 10 2>/dev/null || echo "No logs available"
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
echo "=== Manual Test Command ==="
|
||||||
|
echo "Run this command to manually test a service:"
|
||||||
|
echo ""
|
||||||
|
echo " sudo -u $MPC_USER bash -c 'source $CONFIG_DIR/mpc.env && $BIN_DIR/session-coordinator'"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
# ============================================
|
# ============================================
|
||||||
# Uninstall Command
|
# Uninstall Command
|
||||||
# ============================================
|
# ============================================
|
||||||
|
|
@ -588,6 +679,9 @@ case "${1:-}" in
|
||||||
reconfigure)
|
reconfigure)
|
||||||
reconfigure
|
reconfigure
|
||||||
;;
|
;;
|
||||||
|
debug)
|
||||||
|
debug
|
||||||
|
;;
|
||||||
start)
|
start)
|
||||||
start_services
|
start_services
|
||||||
;;
|
;;
|
||||||
|
|
@ -609,12 +703,13 @@ case "${1:-}" in
|
||||||
*)
|
*)
|
||||||
echo "MPC-System Deployment Script"
|
echo "MPC-System Deployment Script"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Usage: $0 {install|build|reconfigure|start|stop|restart|status|logs|uninstall}"
|
echo "Usage: $0 {install|build|reconfigure|debug|start|stop|restart|status|logs|uninstall}"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " install - Install system dependencies (Go, PostgreSQL, Redis, RabbitMQ)"
|
echo " install - Install system dependencies (Go, PostgreSQL, Redis, RabbitMQ)"
|
||||||
echo " build - Build services and configure infrastructure"
|
echo " build - Build services and configure infrastructure"
|
||||||
echo " reconfigure - Reconfigure PostgreSQL/Redis/RabbitMQ (fix auth issues)"
|
echo " reconfigure - Reconfigure PostgreSQL/Redis/RabbitMQ (fix auth issues)"
|
||||||
|
echo " debug - Show debug information and test connections"
|
||||||
echo " start - Start all MPC services"
|
echo " start - Start all MPC services"
|
||||||
echo " stop - Stop all MPC services"
|
echo " stop - Stop all MPC services"
|
||||||
echo " restart - Restart all MPC services"
|
echo " restart - Restart all MPC services"
|
||||||
|
|
@ -630,6 +725,7 @@ case "${1:-}" in
|
||||||
echo " $0 status # Check status"
|
echo " $0 status # Check status"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Troubleshooting:"
|
echo "Troubleshooting:"
|
||||||
|
echo " $0 debug # Show debug info and test DB connection"
|
||||||
echo " $0 reconfigure # Fix database authentication issues"
|
echo " $0 reconfigure # Fix database authentication issues"
|
||||||
echo " $0 restart # Then restart services"
|
echo " $0 restart # Then restart services"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue