diff --git a/backend/mpc-system/scripts/deploy.sh b/backend/mpc-system/scripts/deploy.sh index a6b8fd57..3242828a 100644 --- a/backend/mpc-system/scripts/deploy.sh +++ b/backend/mpc-system/scripts/deploy.sh @@ -414,8 +414,12 @@ ALLOWED_IPS=192.168.1.111 # Server Configuration MPC_SERVER_ENVIRONMENT=production -MPC_SERVER_HTTP_PORT=8080 -MPC_SERVER_GRPC_PORT=50051 +# NOTE: MPC_SERVER_HTTP_PORT and MPC_SERVER_GRPC_PORT are set per-service in systemd unit files +# Do NOT set them here as they are service-specific: +# session-coordinator: gRPC 50051, HTTP 8081 +# message-router: gRPC 50052, HTTP 8082 +# server-party-1/2/3: HTTP 8083/8084/8085 +# account-service: HTTP 8080 # Internal Service Addresses SESSION_COORDINATOR_ADDR=localhost:50051 @@ -625,6 +629,51 @@ reconfigure() { log_info "Restart services with: $0 restart" } +# ============================================ +# Fix Port Conflicts (remove global port settings from mpc.env) +# ============================================ +fix_ports() { + check_root + + log_info "Fixing port configuration..." + + if [ ! -f "$CONFIG_DIR/mpc.env" ]; then + log_error "Environment file not found: $CONFIG_DIR/mpc.env" + exit 1 + fi + + # Remove MPC_SERVER_HTTP_PORT and MPC_SERVER_GRPC_PORT from mpc.env + # These should be set per-service in systemd unit files, not globally + if grep -q "^MPC_SERVER_HTTP_PORT=" "$CONFIG_DIR/mpc.env"; then + sed -i '/^MPC_SERVER_HTTP_PORT=/d' "$CONFIG_DIR/mpc.env" + log_info "Removed MPC_SERVER_HTTP_PORT from mpc.env" + fi + + if grep -q "^MPC_SERVER_GRPC_PORT=" "$CONFIG_DIR/mpc.env"; then + sed -i '/^MPC_SERVER_GRPC_PORT=/d' "$CONFIG_DIR/mpc.env" + log_info "Removed MPC_SERVER_GRPC_PORT from mpc.env" + fi + + # Add explanatory comment if not already present + if ! grep -q "# Port configuration is per-service" "$CONFIG_DIR/mpc.env"; then + cat >> "$CONFIG_DIR/mpc.env" << 'EOF' + +# Port configuration is per-service (set in systemd unit files): +# session-coordinator: gRPC 50051, HTTP 8081 +# message-router: gRPC 50052, HTTP 8082 +# server-party-1/2/3: HTTP 8083/8084/8085 +# account-service: HTTP 8080 +EOF + log_info "Added port documentation to mpc.env" + fi + + # Reload systemd and restart services + systemctl daemon-reload + + log_info "Port configuration fixed!" + log_info "Restart services with: $0 restart" +} + # ============================================ # Debug Command (troubleshooting) # ============================================ @@ -765,6 +814,9 @@ case "${1:-}" in regenerate-keys) regenerate_keys ;; + fix-ports) + fix_ports + ;; debug) debug ;; @@ -789,13 +841,14 @@ case "${1:-}" in *) echo "MPC-System Deployment Script" echo "" - echo "Usage: $0 {install|build|reconfigure|regenerate-keys|debug|start|stop|restart|status|logs|uninstall}" + echo "Usage: $0 {install|build|reconfigure|regenerate-keys|fix-ports|debug|start|stop|restart|status|logs|uninstall}" echo "" echo "Commands:" echo " install - Install system dependencies (Go, PostgreSQL, Redis, RabbitMQ)" echo " build - Build services and configure infrastructure" echo " reconfigure - Reconfigure PostgreSQL/Redis/RabbitMQ (fix auth issues)" echo " regenerate-keys - Regenerate secure keys (fix placeholder key issues)" + echo " fix-ports - Fix port conflicts (remove global port settings from mpc.env)" echo " debug - Show debug information and test connections" echo " start - Start all MPC services" echo " stop - Stop all MPC services"