From a302da73a930fce13e1abcaa77a4ba93e9472754 Mon Sep 17 00:00:00 2001 From: oib Date: Fri, 6 Mar 2026 10:25:57 +0100 Subject: [PATCH] refactor: migrate blockchain CLI commands to use centralized config and update port assignments - Replace load_multichain_config() with ctx.obj['config'] in all blockchain commands - Update blockchain RPC port from 8003 to 8006 throughout CLI - Add blockchain_rpc_url and wallet_url fields to Config class with environment variable support - Update node status command to use new port logic (8006 for primary, 8026 for dev) - Update installation docs to reflect new blockchain RPC port (8006) - Update --- cli/aitbc_cli/commands/blockchain.py | 65 +-- cli/aitbc_cli/config/__init__.py | 12 +- docs/0_getting_started/2_installation.md | 2 +- .../ENHANCED_SERVICES_IMPLEMENTATION_GUIDE.md | 42 +- docs/1_project/3_infrastructure.md | 154 ++++++- docs/1_project/aitbc.md | 89 +++- docs/1_project/aitbc1.md | 124 +++++- docs/6_architecture/1_system-flow.md | 32 +- scripts/README.md | 203 +++++++++ scripts/check-aitbc-services.sh | 195 +++++++++ scripts/debug-services.sh | 115 +++++ scripts/start-aitbc-dev.sh | 398 ++++++++++++++++++ scripts/start-aitbc-full.sh | 291 +++++++++++++ scripts/stop-aitbc-dev.sh | 142 +++++++ 14 files changed, 1754 insertions(+), 110 deletions(-) create mode 100644 scripts/README.md create mode 100755 scripts/check-aitbc-services.sh create mode 100755 scripts/debug-services.sh create mode 100755 scripts/start-aitbc-dev.sh create mode 100755 scripts/start-aitbc-full.sh create mode 100755 scripts/stop-aitbc-dev.sh diff --git a/cli/aitbc_cli/commands/blockchain.py b/cli/aitbc_cli/commands/blockchain.py index fb3039b7..3035bd24 100644 --- a/cli/aitbc_cli/commands/blockchain.py +++ b/cli/aitbc_cli/commands/blockchain.py @@ -5,14 +5,11 @@ import httpx def _get_node_endpoint(ctx): try: - from ..core.config import load_multichain_config - config = load_multichain_config() - if not config.nodes: - return "http://127.0.0.1:8082" - # Return the first node's endpoint - return list(config.nodes.values())[0].endpoint + config = ctx.obj['config'] + # Use the new blockchain_rpc_url from config + return config.blockchain_rpc_url except: - return "http://127.0.0.1:8082" + return "http://127.0.0.1:8006" # Use new blockchain RPC port from typing import Optional, List from ..utils import output, error @@ -34,12 +31,8 @@ def blockchain(ctx): def blocks(ctx, limit: int, from_height: Optional[int]): """List recent blocks""" try: - from ..core.config import load_multichain_config - config = load_multichain_config() - if not config.nodes: - node_url = "http://127.0.0.1:8003" - else: - node_url = list(config.nodes.values())[0].endpoint + config = ctx.obj['config'] + node_url = config.blockchain_rpc_url # Use new blockchain RPC port # Get blocks from the local blockchain node with httpx.Client() as client: @@ -82,12 +75,8 @@ def blocks(ctx, limit: int, from_height: Optional[int]): def block(ctx, block_hash: str): """Get details of a specific block""" try: - from ..core.config import load_multichain_config - config = load_multichain_config() - if not config.nodes: - node_url = "http://127.0.0.1:8003" - else: - node_url = list(config.nodes.values())[0].endpoint + config = ctx.obj['config'] + node_url = config.blockchain_rpc_url # Use new blockchain RPC port # Try to get block from local blockchain node with httpx.Client() as client: @@ -163,10 +152,10 @@ def status(ctx, node: int): """Get blockchain node status""" config = ctx.obj['config'] - # Map node to RPC URL + # Map node to RPC URL using new port logic node_urls = { - 1: "http://localhost:8003", - 2: "http://localhost:9080/rpc", # Use RPC API with correct endpoint + 1: "http://localhost:8006", # Primary Blockchain RPC + 2: "http://localhost:8026", # Development Blockchain RPC 3: "http://aitbc.keisanki.net/rpc" } @@ -224,12 +213,8 @@ def sync_status(ctx): def peers(ctx): """List connected peers""" try: - from ..core.config import load_multichain_config - config = load_multichain_config() - if not config.nodes: - node_url = "http://127.0.0.1:8003" - else: - node_url = list(config.nodes.values())[0].endpoint + config = ctx.obj['config'] + node_url = config.blockchain_rpc_url # Use new blockchain RPC port # Try to get peers from the local blockchain node with httpx.Client() as client: @@ -258,12 +243,8 @@ def peers(ctx): def info(ctx): """Get blockchain information""" try: - from ..core.config import load_multichain_config - config = load_multichain_config() - if not config.nodes: - node_url = "http://127.0.0.1:8003" - else: - node_url = list(config.nodes.values())[0].endpoint + config = ctx.obj['config'] + node_url = config.blockchain_rpc_url # Use new blockchain RPC port with httpx.Client() as client: # Get head block for basic info @@ -295,12 +276,8 @@ def info(ctx): def supply(ctx): """Get token supply information""" try: - from ..core.config import load_multichain_config - config = load_multichain_config() - if not config.nodes: - node_url = "http://127.0.0.1:8003" - else: - node_url = list(config.nodes.values())[0].endpoint + config = ctx.obj['config'] + node_url = config.blockchain_rpc_url # Use new blockchain RPC port with httpx.Client() as client: response = client.get( @@ -322,12 +299,8 @@ def supply(ctx): def validators(ctx): """List blockchain validators""" try: - from ..core.config import load_multichain_config - config = load_multichain_config() - if not config.nodes: - node_url = "http://127.0.0.1:8003" - else: - node_url = list(config.nodes.values())[0].endpoint + config = ctx.obj['config'] + node_url = config.blockchain_rpc_url # Use new blockchain RPC port with httpx.Client() as client: response = client.get( diff --git a/cli/aitbc_cli/config/__init__.py b/cli/aitbc_cli/config/__init__.py index 9e2a897a..58efb77d 100644 --- a/cli/aitbc_cli/config/__init__.py +++ b/cli/aitbc_cli/config/__init__.py @@ -16,6 +16,8 @@ class Config: role: Optional[str] = None # admin, client, miner, etc. config_dir: Path = field(default_factory=lambda: Path.home() / ".aitbc") config_file: Optional[str] = None + blockchain_rpc_url: str = "http://127.0.0.1:8006" + wallet_url: str = "http://127.0.0.1:8002" def __post_init__(self): """Initialize configuration""" @@ -39,6 +41,10 @@ class Config: self.api_key = os.getenv("AITBC_API_KEY") if os.getenv("AITBC_ROLE"): self.role = os.getenv("AITBC_ROLE") + if os.getenv("AITBC_BLOCKCHAIN_RPC_URL"): + self.blockchain_rpc_url = os.getenv("AITBC_BLOCKCHAIN_RPC_URL") + if os.getenv("AITBC_WALLET_URL"): + self.wallet_url = os.getenv("AITBC_WALLET_URL") def load_from_file(self): """Load configuration from YAML file""" @@ -50,6 +56,8 @@ class Config: self.coordinator_url = data.get('coordinator_url', self.coordinator_url) self.api_key = data.get('api_key', self.api_key) self.role = data.get('role', self.role) + self.blockchain_rpc_url = data.get('blockchain_rpc_url', self.blockchain_rpc_url) + self.wallet_url = data.get('wallet_url', self.wallet_url) except Exception as e: print(f"Warning: Could not load config file: {e}") @@ -63,7 +71,9 @@ class Config: data = { 'coordinator_url': self.coordinator_url, - 'api_key': self.api_key + 'api_key': self.api_key, + 'blockchain_rpc_url': self.blockchain_rpc_url, + 'wallet_url': self.wallet_url } if self.role: diff --git a/docs/0_getting_started/2_installation.md b/docs/0_getting_started/2_installation.md index 8d11cf3b..b1f9bccb 100644 --- a/docs/0_getting_started/2_installation.md +++ b/docs/0_getting_started/2_installation.md @@ -70,7 +70,7 @@ Create `apps/blockchain-node/.env`: ```env CHAIN_ID=ait-devnet RPC_BIND_HOST=0.0.0.0 -RPC_BIND_PORT=8080 +RPC_BIND_PORT=8006 # Updated to new blockchain RPC port MEMPOOL_BACKEND=database ``` diff --git a/docs/0_getting_started/ENHANCED_SERVICES_IMPLEMENTATION_GUIDE.md b/docs/0_getting_started/ENHANCED_SERVICES_IMPLEMENTATION_GUIDE.md index b3d12849..a42fb105 100644 --- a/docs/0_getting_started/ENHANCED_SERVICES_IMPLEMENTATION_GUIDE.md +++ b/docs/0_getting_started/ENHANCED_SERVICES_IMPLEMENTATION_GUIDE.md @@ -2,7 +2,7 @@ ## πŸš€ Overview -This guide provides step-by-step instructions for implementing and deploying the AITBC Enhanced Services, including 7 new services running on ports 8002-8007 with systemd integration. +This guide provides step-by-step instructions for implementing and deploying the AITBC Enhanced Services, including 7 new services running on ports 8010-8017 with systemd integration. ## πŸ“‹ Prerequisites @@ -128,22 +128,26 @@ cd /opt/aitbc/apps/coordinator-api | Service | Port | Description | Resources | Status | |---------|------|-------------|------------|--------| -| Multi-Modal Agent | 8002 | Text, image, audio, video processing | 2GB RAM, 200% CPU | βœ… | -| GPU Multi-Modal | 8003 | CUDA-optimized attention mechanisms | 4GB RAM, 300% CPU | βœ… | -| Modality Optimization | 8004 | Specialized optimization strategies | 1GB RAM, 150% CPU | βœ… | -| Adaptive Learning | 8005 | Reinforcement learning frameworks | 3GB RAM, 250% CPU | βœ… | -| Enhanced Marketplace | 8006 | Royalties, licensing, verification | 2GB RAM, 200% CPU | βœ… | -| OpenClaw Enhanced | 8007 | Agent orchestration, edge computing | 2GB RAM, 200% CPU | βœ… | +| Multi-Modal Agent | 8010 | Text, image, audio, video processing | 2GB RAM, 200% CPU | βœ… | +| GPU Multi-Modal | 8011 | CUDA-optimized attention mechanisms | 4GB RAM, 300% CPU | βœ… | +| Modality Optimization | 8012 | Specialized optimization strategies | 1GB RAM, 150% CPU | βœ… | +| Adaptive Learning | 8013 | Reinforcement learning frameworks | 3GB RAM, 250% CPU | βœ… | +| Enhanced Marketplace | 8014 | Royalties, licensing, verification | 2GB RAM, 200% CPU | βœ… | +| OpenClaw Enhanced | 8015 | Agent orchestration, edge computing | 2GB RAM, 200% CPU | βœ… | +| Web UI Service | 8016 | Web interface for all services | 1GB RAM, 100% CPU | βœ… | +| Geographic Load Balancer | 8017 | Geographic distribution | 1GB RAM, 100% CPU | βœ… | ### Health Check Endpoints ```bash # Check all services -curl http://localhost:8002/health # Multi-Modal -curl http://localhost:8003/health # GPU Multi-Modal -curl http://localhost:8004/health # Modality Optimization -curl http://localhost:8005/health # Adaptive Learning -curl http://localhost:8006/health # Enhanced Marketplace -curl http://localhost:8007/health # OpenClaw Enhanced +curl http://localhost:8010/health # Multi-Modal +curl http://localhost:8011/health # GPU Multi-Modal +curl http://localhost:8012/health # Modality Optimization +curl http://localhost:8013/health # Adaptive Learning +curl http://localhost:8014/health # Enhanced Marketplace +curl http://localhost:8015/health # OpenClaw Enhanced +curl http://localhost:8016/health # Web UI Service +curl http://localhost:8017/health # Geographic Load Balancer ``` ## πŸ§ͺ Testing @@ -158,12 +162,12 @@ python demo_client_miner_workflow.py ### 2. Multi-Modal Processing Test ```bash # Test text processing -curl -X POST http://localhost:8002/process \ +curl -X POST http://localhost:8010/process \ -H "Content-Type: application/json" \ -d '{"modality": "text", "input": "Hello AITBC!"}' # Test image processing -curl -X POST http://localhost:8002/process \ +curl -X POST http://localhost:8010/process \ -H "Content-Type: application/json" \ -d '{"modality": "image", "input": "base64_encoded_image"}' ``` @@ -171,7 +175,7 @@ curl -X POST http://localhost:8002/process \ ### 3. GPU Performance Test ```bash # Test GPU multi-modal service -curl -X POST http://localhost:8003/process \ +curl -X POST http://localhost:8011/process \ -H "Content-Type: application/json" \ -d '{"modality": "text", "input": "GPU accelerated test", "use_gpu": true}' ``` @@ -270,7 +274,7 @@ ls -la /dev/nvidia* netstat -tuln | grep :800 # Kill conflicting processes -sudo fuser -k 8002/tcp +sudo fuser -k 8010/tcp ``` #### 4. Memory Issues @@ -318,10 +322,10 @@ sudo systemctl edit aitbc-multimodal.service ### Monitoring Metrics ```bash # Response time metrics -curl -w "@curl-format.txt" -o /dev/null -s http://localhost:8002/health +curl -w "@curl-format.txt" -o /dev/null -s http://localhost:8010/health # Throughput testing -ab -n 1000 -c 10 http://localhost:8002/health +ab -n 1000 -c 10 http://localhost:8010/health # GPU utilization nvidia-smi dmon -s u diff --git a/docs/1_project/3_infrastructure.md b/docs/1_project/3_infrastructure.md index 2cca8341..7aad92f9 100644 --- a/docs/1_project/3_infrastructure.md +++ b/docs/1_project/3_infrastructure.md @@ -47,15 +47,18 @@ Internet β†’ aitbc.bubuit.net (HTTPS :443) β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` -## Port Logic Implementation (March 4, 2026) +## Port Logic Implementation (Updated March 6, 2026) -### **Core Services (8000-8003)** +### **Core Services (8000-8002)** - **Port 8000**: Coordinator API βœ… PRODUCTION READY - **Port 8001**: Exchange API βœ… PRODUCTION READY -- **Port 8002**: Blockchain Node (internal) βœ… PRODUCTION READY -- **Port 8003**: Blockchain RPC βœ… PRODUCTION READY +- **Port 8002**: Wallet Service βœ… PRODUCTION READY (aitbc-wallet.service - localhost + containers) -### **Enhanced Services (8010-8017)** +### **Blockchain Services (8005-8006)** +- **Port 8005**: Primary Blockchain Node βœ… PRODUCTION READY (aitbc-blockchain-node.service - localhost + containers) +- **Port 8006**: Primary Blockchain RPC βœ… PRODUCTION READY (aitbc-blockchain-rpc.service - localhost + containers) + +### **Level 2 Services (8010-8017) - NEW STANDARD** - **Port 8010**: Multimodal GPU Service βœ… PRODUCTION READY (CPU-only mode) - **Port 8011**: GPU Multimodal Service βœ… PRODUCTION READY (CPU-only mode) - **Port 8012**: Modality Optimization Service βœ… PRODUCTION READY @@ -65,8 +68,33 @@ Internet β†’ aitbc.bubuit.net (HTTPS :443) - **Port 8016**: Web UI Service βœ… PRODUCTION READY - **Port 8017**: Geographic Load Balancer βœ… PRODUCTION READY +### **Mock & Test Services (8020-8029)** +- **Port 8020**: Mock Coordinator API βœ… TESTING READY +- **Port 8021**: Coordinator API (dev) βœ… TESTING READY +- **Port 8022**: Test Blockchain Node (localhost) βœ… TESTING READY +- **Port 8023**: Mock Exchange API βœ… TESTING READY +- **Port 8024**: Mock Blockchain RPC βœ… TESTING READY +- **Port 8025**: Development Blockchain Node βœ… TESTING READY (aitbc-blockchain-node-dev.service) +- **Port 8026**: Development Blockchain RPC βœ… TESTING READY (aitbc-blockchain-rpc-dev.service) +- **Port 8027**: Load Testing Endpoint βœ… TESTING READY +- **Port 8028**: Integration Test API βœ… TESTING READY +- **Port 8029**: Performance Monitor βœ… TESTING READY + +### **Container Services (8080-8089) - LEGACY** +- **Port 8080**: Container Coordinator API (aitbc) ⚠️ LEGACY - Use port 8000-8003 range +- **Port 8081**: Container Blockchain Node 1 ⚠️ LEGACY - Use port 8010+ range +- **Port 8082**: Container Exchange API ⚠️ LEGACY - Use port 8010+ range +- **Port 8083**: Container Wallet Daemon ⚠️ LEGACY - Use port 8010+ range +- **Port 8084**: Container Blockchain Node 2 ⚠️ LEGACY - Use port 8010+ range +- **Port 8085**: Container Explorer UI ⚠️ LEGACY - Use port 8010+ range +- **Port 8086**: Container Marketplace ⚠️ LEGACY - Use port 8010+ range +- **Port 8087**: Container Miner Dashboard ⚠️ LEGACY - Use port 8010+ range +- **Port 8088**: Container Load Balancer ⚠️ LEGACY - Use port 8010+ range +- **Port 8089**: Container Debug API ⚠️ LEGACY - Use port 8010+ range + ### **Legacy Ports (Decommissioned)** -- **Port 8080**: No longer used by AITBC +- **Port 8003**: Previously Primary Blockchain RPC - Decommissioned (moved to port 8006) +- **Port 8090**: No longer used by AITBC - **Port 9080**: Successfully decommissioned - **Port 8009**: No longer in use @@ -644,3 +672,117 @@ WALLET_ENCRYPTION_KEY= HOST=0.0.0.0 # For container access PORT=8010-8017 # Enhanced services port range ``` + +### Container Access & Port Logic (Updated March 6, 2026) + +#### **SSH-Based Container Access** +```bash +# Access aitbc container +ssh aitbc-cascade + +# Access aitbc1 container +ssh aitbc1-cascade + +# Check services in containers +ssh aitbc-cascade 'systemctl list-units | grep aitbc-' +ssh aitbc1-cascade 'systemctl list-units | grep aitbc-' + +# Debug specific services +ssh aitbc-cascade 'systemctl status aitbc-coordinator-api' +ssh aitbc1-cascade 'systemctl status aitbc-wallet' +``` + +#### **Port Distribution Strategy - NEW STANDARD** +```bash +# === NEW STANDARD PORT LOGIC === + +# Core Services (8000-8003) - NEW STANDARD +- Port 8000: Coordinator API (local) βœ… NEW STANDARD +- Port 8001: Exchange API (local) βœ… NEW STANDARD +- Port 8002: Blockchain Node (local) βœ… NEW STANDARD +- Port 8003: Blockchain RPC (local) βœ… NEW STANDARD + +# Blockchain Services (8004-8005) - PRODUCTION READY +- Port 8004: Primary Blockchain Node βœ… PRODUCTION READY (aitbc-blockchain-node.service) +- Port 8005: Blockchain RPC 2 βœ… PRODUCTION READY + +# Level 2 Services (8010-8017) - NEW STANDARD +- Port 8010: Multimodal GPU Service βœ… NEW STANDARD +- Port 8011: GPU Multimodal Service βœ… NEW STANDARD +- Port 8012: Modality Optimization Service βœ… NEW STANDARD +- Port 8013: Adaptive Learning Service βœ… NEW STANDARD +- Port 8014: Marketplace Enhanced Service βœ… NEW STANDARD +- Port 8015: OpenClaw Enhanced Service βœ… NEW STANDARD +- Port 8016: Web UI Service βœ… NEW STANDARD +- Port 8017: Geographic Load Balancer βœ… NEW STANDARD + +# Mock & Test Services (8020-8029) - NEW STANDARD +- Port 8020: Mock Coordinator API βœ… NEW STANDARD +- Port 8021: Coordinator API (dev) βœ… NEW STANDARD +- Port 8022: Test Blockchain Node (localhost) βœ… NEW STANDARD +- Port 8025: Development Blockchain Node βœ… NEW STANDARD (aitbc-blockchain-node-dev.service) +- Port 8026-8029: Additional testing services βœ… NEW STANDARD + +# === LEGACY PORTS (DEPRECATED) === + +# Legacy Container Services (8080-8089) - DEPRECATED +- Port 8080-8089: All container services ⚠️ DEPRECATED - Use 8000+ and 8010+ ranges +``` + +#### **Service Naming Convention** +```bash +# === STANDARDIZED SERVICE NAMES === + +# Primary Production Services: +βœ… aitbc-blockchain-node.service (port 8005) - Primary blockchain node +βœ… aitbc-blockchain-rpc.service (port 8006) - Primary blockchain RPC (localhost + containers) +βœ… aitbc-coordinator-api.service (port 8000) - Main coordinator API +βœ… aitbc-exchange-api.service (port 8001) - Exchange API +βœ… aitbc-wallet.service (port 8002) - Wallet Service (localhost + containers) + +# Development/Test Services: +βœ… aitbc-blockchain-node-dev.service (port 8025) - Development blockchain node +βœ… aitbc-blockchain-rpc-dev.service (port 8026) - Development blockchain RPC +βœ… aitbc-coordinator-api-dev.service (port 8021) - Development coordinator API + +# Container Locations: +βœ… localhost (at1): Primary services + development services +βœ… aitbc container: Primary services + development services +βœ… aitbc1 container: Primary services + development services +``` + +#### **Port Conflict Resolution** +```bash +# Updated port assignments - NO CONFLICTS: +# Local services use 8000-8003 range (core services) +# Blockchain services use 8004-8005 range (primary blockchain nodes) +# Level 2 services use 8010-8017 range (enhanced services) +# Mock & test services use 8020-8029 range (development services) + +# Check port usage +netstat -tlnp | grep -E ":(800[0-5]|801[0-7]|802[0-9])" +ssh aitbc-cascade 'netstat -tlnp | grep -E ":(800[0-5]|801[0-7]|802[0-9])" +ssh aitbc1-cascade 'netstat -tlnp | grep -E ":(800[0-5]|801[0-7]|802[0-9])" + +# Service Management Commands: +# Primary services: +systemctl status aitbc-blockchain-node.service # localhost +systemctl status aitbc-blockchain-rpc.service # localhost (port 8006) +systemctl status aitbc-wallet.service # localhost (port 8002) +ssh aitbc-cascade 'systemctl status aitbc-blockchain-node.service' # aitbc container +ssh aitbc1-cascade 'systemctl status aitbc-blockchain-node.service' # aitbc1 container + +# Wallet services: +ssh aitbc-cascade 'systemctl status aitbc-wallet.service' # port 8002 +ssh aitbc1-cascade 'systemctl status aitbc-wallet.service' # port 8002 + +# RPC services: +ssh aitbc-cascade 'systemctl status aitbc-blockchain-rpc.service' # port 8006 +ssh aitbc1-cascade 'systemctl status aitbc-blockchain-rpc.service' # port 8006 +ssh aitbc-cascade 'systemctl status aitbc-blockchain-rpc-dev.service' # port 8026 +ssh aitbc1-cascade 'systemctl status aitbc-blockchain-rpc-dev.service' # port 8026 + +# Development services: +ssh aitbc-cascade 'systemctl status aitbc-blockchain-node-dev.service' +ssh aitbc1-cascade 'systemctl status aitbc-blockchain-node-dev.service' +``` diff --git a/docs/1_project/aitbc.md b/docs/1_project/aitbc.md index 50517604..55e99f8d 100644 --- a/docs/1_project/aitbc.md +++ b/docs/1_project/aitbc.md @@ -1,8 +1,10 @@ -# AITBC Platform Deployment Guide +# AITBC Server Deployment Guide ## Overview -This guide provides comprehensive deployment instructions for the AITBC (AI Trading Blockchain Compute) platform, including infrastructure requirements, service configurations, and troubleshooting procedures. **Updated for the new port logic implementation (8000-8003, 8010-8017) and production-ready codebase.** +This guide provides comprehensive deployment instructions for the **aitbc server** (primary container), including infrastructure requirements, service configurations, and troubleshooting procedures. **Updated for the new port logic implementation (8000-8002, 8005-8006) and production-ready codebase.** + +**Note**: This documentation is specific to the aitbc server. For aitbc1 server documentation, see [aitbc1.md](./aitbc1.md). ## System Requirements @@ -21,12 +23,14 @@ This guide provides comprehensive deployment instructions for the AITBC (AI Trad - **Database**: SQLite (default) or PostgreSQL (production) ### **Network Requirements** -- **Core Services Ports**: 8000-8003 (must be available) +- **Core Services Ports**: 8000-8002 (must be available) - Port 8000: Coordinator API - Port 8001: Exchange API - - Port 8002: Blockchain Node (internal) - - Port 8003: Blockchain RPC -- **Enhanced Services Ports**: 8010-8017 (optional - not required for CPU-only deployment) + - Port 8002: Wallet Service +- **Blockchain Services Ports**: 8005-8006 (must be available) + - Port 8005: Primary Blockchain Node + - Port 8006: Primary Blockchain RPC +- **Level 2 Services Ports**: 8010-8017 (optional - not required for CPU-only deployment) - Note: Enhanced services disabled for aitbc server (no GPU access) - Port 8010: Multimodal GPU (CPU-only mode) - DISABLED - Port 8011: GPU Multimodal (CPU-only mode) - DISABLED @@ -36,9 +40,80 @@ This guide provides comprehensive deployment instructions for the AITBC (AI Trad - Port 8015: OpenClaw Enhanced - DISABLED - Port 8016: Web UI - DISABLED - Port 8017: Geographic Load Balancer - DISABLED - - **Firewall**: Managed by firehol on at1 host (container networking handled by incus) +- **Mock & Test Services Ports**: 8020-8029 (development and testing) + - Port 8025: Development Blockchain Node + - Port 8026: Development Blockchain RPC +- **Legacy Container Ports**: 8080-8089 (deprecated - use new port ranges) +- **Firewall**: Managed by firehol on at1 host (container networking handled by incus) - **SSL/TLS**: Recommended for production deployments +### **Container Access & SSH Management (Updated March 6, 2026)** + +#### **SSH-Based Container Access** +```bash +# Access aitbc server (primary container) +ssh aitbc-cascade + +# Check aitbc server status +ssh aitbc-cascade 'systemctl status' + +# List AITBC services on aitbc server +ssh aitbc-cascade 'systemctl list-units | grep aitbc-' +``` + +#### **Service Management via SSH** +```bash +# Start/stop services on aitbc server +ssh aitbc-cascade 'sudo systemctl start aitbc-coordinator-api' +ssh aitbc-cascade 'sudo systemctl stop aitbc-wallet' + +# Check service logs on aitbc server +ssh aitbc-cascade 'sudo journalctl -f -u aitbc-coordinator-api' + +# Debug service issues on aitbc server +ssh aitbc-cascade 'sudo systemctl status aitbc-coordinator-api' +ssh aitbc-cascade 'sudo systemctl status aitbc-wallet' + +# Check blockchain services on aitbc server +ssh aitbc-cascade 'sudo systemctl status aitbc-blockchain-node' +ssh aitbc-cascade 'sudo systemctl status aitbc-blockchain-rpc' + +# Check development services on aitbc server +ssh aitbc-cascade 'sudo systemctl status aitbc-blockchain-node-dev' +ssh aitbc-cascade 'sudo systemctl status aitbc-blockchain-rpc-dev' +``` + +#### **Port Distribution Strategy (Updated March 6, 2026)** +```bash +# NEW SUSTAINABLE PORT LOGIC + +# Core Services (8000-8002): +- Port 8000: Coordinator API (localhost + containers) +- Port 8001: Exchange API (localhost + containers) +- Port 8002: Wallet Service (localhost + containers) + +# Blockchain Services (8005-8006): +- Port 8005: Primary Blockchain Node (localhost + containers) +- Port 8006: Primary Blockchain RPC (localhost + containers) + +# Level 2 Services (8010-8017): +- Port 8010-8017: Enhanced services (DISABLED for CPU-only deployment) + +# Mock & Test Services (8020-8029): +- Port 8025: Development Blockchain Node (localhost + containers) +- Port 8026: Development Blockchain RPC (containers) + +# Legacy Ports (8080-8089): +- Port 8080-8089: DEPRECATED - use new port ranges above + +# Service Naming Convention: +βœ… aitbc-blockchain-node.service (port 8005) +βœ… aitbc-blockchain-rpc.service (port 8006) +βœ… aitbc-wallet.service (port 8002) +βœ… aitbc-blockchain-node-dev.service (port 8025) +βœ… aitbc-blockchain-rpc-dev.service (port 8026) +``` + ## Architecture Overview ``` diff --git a/docs/1_project/aitbc1.md b/docs/1_project/aitbc1.md index 37aee7de..c8b23b08 100644 --- a/docs/1_project/aitbc1.md +++ b/docs/1_project/aitbc1.md @@ -1,16 +1,18 @@ -# AITBC1 Deployment Notes +# AITBC1 Server Deployment Guide ## Overview -This document contains specific deployment notes and considerations for deploying the AITBC platform on the **aitbc** server. These notes complement the general deployment guide with server-specific configurations and troubleshooting. **Updated for optimized CPU-only deployment with enhanced services disabled.** +This document contains specific deployment notes and considerations for deploying the AITBC platform on the **aitbc1 server** (secondary container). These notes complement the general deployment guide with server-specific configurations and troubleshooting. **Updated for optimized CPU-only deployment with enhanced services disabled.** + +**Note**: This documentation is specific to the aitbc1 server. For aitbc server documentation, see [aitbc.md](./aitbc.md). ## Server Specifications -### **aitbc Server Details** -- **Hostname**: aitbc (container) -- **IP Address**: 10.1.223.1 (container IP) -- **Operating System**: Debian 13 Trixie (primary development environment) -- **Access Method**: SSH via aitbc-cascade proxy +### **aitbc1 Server Details** +- **Hostname**: aitbc1 (container) +- **IP Address**: 10.1.223.2 (container IP) +- **Operating System**: Debian 13 Trixie (secondary development environment) +- **Access Method**: SSH via aitbc1-cascade proxy - **GPU Access**: None (CPU-only mode) - **Miner Service**: Not needed - **Enhanced Services**: Disabled (optimized deployment) @@ -20,13 +22,107 @@ This document contains specific deployment notes and considerations for deployin ### **Network Architecture** ``` -Internet β†’ aitbc-cascade (Proxy) β†’ aitbc (Container) - SSL Termination Application Server - Port 443/80 Port 8000-8003 (Core Services Only) +Internet β†’ aitbc1-cascade (Proxy) β†’ aitbc1 (Container) + SSH Access Application Server + Port 22/443 Port 8000-8002 (Core Services) + Port 8005-8006 Blockchain Services + Port 8025-8026 Development Services ``` **Note**: Enhanced services ports 8010-8017 are disabled for CPU-only deployment +### **SSH-Based Container Access (Updated March 6, 2026)** + +#### **Primary Access Methods** +```bash +# Access aitbc1 server (secondary container) +ssh aitbc1-cascade + +# Check aitbc1 server connectivity +ssh aitbc1-cascade 'echo "Container accessible"' +``` + +#### **Service Management via SSH** +```bash +# List all AITBC services on aitbc1 server +ssh aitbc1-cascade 'systemctl list-units | grep aitbc-' + +# Check specific service status on aitbc1 server +ssh aitbc1-cascade 'systemctl status aitbc-coordinator-api' +ssh aitbc1-cascade 'systemctl status aitbc-wallet' + +# Start/stop services on aitbc1 server +ssh aitbc1-cascade 'sudo systemctl start aitbc-coordinator-api' +ssh aitbc1-cascade 'sudo systemctl stop aitbc-wallet' + +# View service logs on aitbc1 server +ssh aitbc1-cascade 'sudo journalctl -f -u aitbc-coordinator-api' +ssh aitbc1-cascade 'sudo journalctl -f -u aitbc-blockchain-node' + +# Check blockchain services on aitbc1 server +ssh aitbc1-cascade 'sudo systemctl status aitbc-blockchain-node' +ssh aitbc1-cascade 'sudo systemctl status aitbc-blockchain-rpc' + +# Check development services on aitbc1 server +ssh aitbc1-cascade 'sudo systemctl status aitbc-blockchain-node-dev' +ssh aitbc1-cascade 'sudo systemctl status aitbc-blockchain-rpc-dev' +``` + +#### **Port Distribution & Conflict Resolution (Updated March 6, 2026)** +```bash +# NEW SUSTAINABLE PORT LOGIC - NO CONFLICTS + +# Core Services (8000-8002): +- Port 8000: Coordinator API (localhost + containers) +- Port 8001: Exchange API (localhost + containers) +- Port 8002: Wallet Service (localhost + containers) + +# Blockchain Services (8005-8006): +- Port 8005: Primary Blockchain Node (localhost + containers) +- Port 8006: Primary Blockchain RPC (localhost + containers) + +# Level 2 Services (8010-8017): +- Port 8010-8017: Enhanced services (DISABLED for CPU-only deployment) + +# Mock & Test Services (8020-8029): +- Port 8025: Development Blockchain Node (localhost + containers) +- Port 8026: Development Blockchain RPC (containers) + +# Legacy Ports (8080-8089): +- Port 8080-8089: DEPRECATED - use new port ranges above + +# Service Naming Convention: +βœ… aitbc-blockchain-node.service (port 8005) +βœ… aitbc-blockchain-rpc.service (port 8006) +βœ… aitbc-wallet.service (port 8002) +βœ… aitbc-blockchain-node-dev.service (port 8025) +βœ… aitbc-blockchain-rpc-dev.service (port 8026) + +# Resolution Strategy: +# 1. New port logic eliminates all conflicts +# 2. Sequential port assignment for related services +# 3. Clear separation between production and development services +``` + +#### **Debug Container Service Issues** +```bash +# Debug coordinator API port conflict +ssh aitbc-cascade 'sudo systemctl status aitbc-coordinator-api' +ssh aitbc-cascade 'sudo journalctl -u aitbc-coordinator-api -n 20' + +# Debug wallet service issues +ssh aitbc-cascade 'sudo systemctl status aitbc-wallet' +ssh aitbc-cascade 'sudo journalctl -u aitbc-wallet -n 20' + +# Check port usage in containers +ssh aitbc-cascade 'sudo netstat -tlnp | grep :800' +ssh aitbc1-cascade 'sudo netstat -tlnp | grep :800' + +# Test service endpoints +ssh aitbc-cascade 'curl -s http://localhost:8001/health' +ssh aitbc1-cascade 'curl -s http://localhost:8002/health' +``` + ## Pre-Deployment Checklist ### **βœ… Server Preparation** @@ -334,19 +430,19 @@ else echo "Database: ❌ (Missing)" fi -# Container access test +# Container access test for aitbc1 server echo -e "\nContainer Access Test:" -curl -s -o /dev/null -w "%{http_code}" "http://10.1.223.1:8017/health" | grep -q "200" && echo "Container Access: βœ…" || echo "Container Access: ❌" +curl -s -o /dev/null -w "%{http_code}" "http://10.1.223.2:8017/health" | grep -q "200" && echo "Container Access: βœ…" || echo "Container Access: ❌" EOF chmod +x /opt/aitbc/scripts/monitor-aitbc.sh ``` -## Backup Strategy for aitbc +## Backup Strategy for aitbc1 ### **Automated Backup Script** ```bash -# /opt/aitbc/scripts/backup-aitbc.sh +# /opt/aitbc/scripts/backup-aitbc1.sh #!/bin/bash BACKUP_DIR="/opt/aitbc/backups" DATE=$(date +%Y%m%d_%H%M%S) diff --git a/docs/6_architecture/1_system-flow.md b/docs/6_architecture/1_system-flow.md index 6803fa15..c4b1a12d 100644 --- a/docs/6_architecture/1_system-flow.md +++ b/docs/6_architecture/1_system-flow.md @@ -8,7 +8,7 @@ This document illustrates the complete flow of a job submission through the CLI β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ CLI β”‚ β”‚ Client β”‚ β”‚Coordinator β”‚ β”‚ Blockchain β”‚ β”‚ Miner β”‚ β”‚ Ollama β”‚ β”‚ Wrapper │────▢│ Python │────▢│ Service │────▢│ Node │────▢│ Daemon │────▢│ Server β”‚ -β”‚(aitbc-cli.sh)β”‚ β”‚ (client.py) β”‚ β”‚ (port 18000)β”‚ β”‚ (RPC:26657) β”‚ β”‚ (port 18001)β”‚ β”‚ (port 11434)β”‚ +β”‚(aitbc-cli.sh)β”‚ β”‚ (client.py) β”‚ β”‚ (port 8000) β”‚ β”‚ (RPC:8006) β”‚ β”‚ (port 8005) β”‚ β”‚ (port 11434)β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` @@ -24,7 +24,7 @@ This document illustrates the complete flow of a job submission through the CLI **Internal Process:** 1. Bash script (`aitbc-cli.sh`) parses arguments 2. Sets environment variables: - - `AITBC_URL=http://127.0.0.1:18000` + - `AITBC_URL=http://127.0.0.1:8000` - `CLIENT_KEY=${CLIENT_API_KEY}` 3. Calls Python client: `python3 cli/client.py --url $AITBC_URL --api-key $CLIENT_KEY submit inference --prompt "..."` @@ -50,7 +50,7 @@ This document illustrates the complete flow of a job submission through the CLI **HTTP Request:** ```http POST /v1/jobs -Host: 127.0.0.1:18000 +Host: 127.0.0.1:8000 Content-Type: application/json X-Api-Key: ${CLIENT_API_KEY} @@ -61,7 +61,7 @@ X-Api-Key: ${CLIENT_API_KEY} } ``` -**Coordinator Service (Port 18000):** +**Coordinator Service (Port 8000):** 1. Receives HTTP request 2. Validates API key and job parameters 3. Generates unique job ID: `job_123456` @@ -112,10 +112,10 @@ X-Api-Key: ${CLIENT_API_KEY} - Select based on stake, reputation, capacity 3. Selected miner: `${MINER_API_KEY}` -**Coordinator β†’ Miner Daemon (Port 18001):** +**Coordinator β†’ Miner Daemon (Port 8005):** ```http POST /v1/jobs/assign -Host: 127.0.0.1:18001 +Host: 127.0.0.1:8005 Content-Type: application/json X-Api-Key: ${ADMIN_API_KEY} @@ -132,7 +132,7 @@ X-Api-Key: ${ADMIN_API_KEY} ### 6. Miner Processing -**Miner Daemon (Port 18001):** +**Miner Daemon (Port 8005):** 1. Receives job assignment 2. Updates job status to `running` 3. Notifies coordinator: @@ -178,10 +178,10 @@ Content-Type: application/json ### 8. Result Submission to Coordinator -**Miner β†’ Coordinator (Port 18000):** +**Miner β†’ Coordinator (Port 8000):** ```http POST /v1/jobs/job_123456/complete -Host: 127.0.0.1:18000 +Host: 127.0.0.1:8000 Content-Type: application/json X-Miner-Key: ${MINER_API_KEY} @@ -243,7 +243,7 @@ X-Miner-Key: ${MINER_API_KEY} **HTTP Request:** ```http GET /v1/jobs/job_123456 -Host: 127.0.0.1:18000 +Host: 127.0.0.1:8000 X-Api-Key: ${CLIENT_API_KEY} ``` @@ -276,9 +276,9 @@ Cost: 0.25 AITBC |-----------|------|----------|----------------| | CLI Wrapper | N/A | Bash | User interface, argument parsing | | Client Python | N/A | Python | HTTP client, job formatting | -| Coordinator | 18000 | HTTP/REST | Job management, API gateway | -| Blockchain Node | 26657 | JSON-RPC | Transaction processing, consensus | -| Miner Daemon | 18001 | HTTP/REST | Job execution, GPU management | +| Coordinator | 8000 | HTTP/REST | Job management, API gateway | +| Blockchain Node | 8006 | JSON-RPC | Transaction processing, consensus | +| Miner Daemon | 8005 | HTTP/REST | Job execution, GPU management | | Ollama Server | 11434 | HTTP/REST | AI model inference | ## Message Flow Timeline @@ -286,12 +286,12 @@ Cost: 0.25 AITBC ``` 0s: User submits CLI command └─> 0.1s: Python client called - └─> 0.2s: HTTP POST to Coordinator (port 18000) + └─> 0.2s: HTTP POST to Coordinator (port 8000) └─> 0.3s: Coordinator validates and creates job - └─> 0.4s: RPC to Blockchain (port 26657) + └─> 0.4s: RPC to Blockchain (port 8006) └─> 0.5s: Transaction in mempool └─> 1.0s: Job queued for miner - └─> 2.0s: Miner assigned (port 18001) + └─> 2.0s: Miner assigned (port 8005) └─> 2.1s: Miner accepts job └─> 2.2s: Ollama request (port 11434) └─> 14.7s: Inference complete (12.5s processing) diff --git a/scripts/README.md b/scripts/README.md new file mode 100644 index 00000000..4c3fbaa4 --- /dev/null +++ b/scripts/README.md @@ -0,0 +1,203 @@ +# AITBC Development Environment Scripts + +This directory contains scripts for managing the AITBC development environment, including incus containers and systemd services. + +## πŸ“‹ Available Scripts + +### πŸ”§ `start-aitbc-dev.sh` +Starts incus containers and AITBC systemd services on localhost. + +**Features:** +- Starts incus containers: `aitbc` and `aitbc1` +- Starts all local systemd services matching `aitbc-*` +- Checks service health and port status +- Tests health endpoints +- Provides colored output and status reporting + +**Usage:** +```bash +./scripts/start-aitbc-dev.sh +``` + +### πŸ›‘ `stop-aitbc-dev.sh` +Stops incus containers and AITBC systemd services on localhost. + +**Features:** +- Stops incus containers: `aitbc` and `aitbc1` +- Stops all local systemd services matching `aitbc-*` +- Verifies services are stopped +- Provides colored output and status reporting + +**Usage:** +```bash +./scripts/stop-aitbc-dev.sh +``` + +### πŸš€ `start-aitbc-full.sh` +Comprehensive startup script for the complete AITBC development environment. + +**Features:** +- Starts incus containers: `aitbc` and `aitbc1` +- Starts services inside containers +- Starts all local systemd services matching `aitbc-*` +- Tests connectivity to container services +- Provides detailed status reporting +- Shows container IP addresses +- Tests health endpoints + +**Services Started:** +- **Local Services:** All `aitbc-*` systemd services +- **Container Services:** + - `aitbc-coordinator-api` + - `aitbc-wallet-daemon` + - `aitbc-blockchain-node` + +**Usage:** +```bash +./scripts/start-aitbc-full.sh +``` + +## 🎯 Prerequisites + +### Required Commands: +- `incus` - Container management +- `systemctl` - Systemd service management +- `curl` - Health endpoint testing +- `netstat` - Port checking + +### Required Containers: +The scripts expect these incus containers to exist: +- `aitbc` +- `aitbc1` + +### Required Services: +The scripts look for systemd services matching the pattern `aitbc-*`. + +## πŸ“Š Service Ports + +| Port | Service | Description | +|------|---------|-------------| +| 8001 | Coordinator API | Main API service | +| 8002 | Wallet Daemon | Wallet management | +| 8003 | Blockchain RPC | Blockchain node RPC | +| 8000 | Coordinator API (alt) | Alternative API | +| 8081 | Blockchain Node 1 | Blockchain instance | +| 8082 | Blockchain Node 2 | Blockchain instance | +| 8006 | Coordinator API (dev) | Development API | + +## πŸ” Health Endpoints + +The scripts test these health endpoints: +- `http://localhost:8001/health` - Coordinator API +- `http://localhost:8002/health` - Wallet Daemon +- `http://localhost:8003/health` - Blockchain RPC + +## πŸ“ Output Examples + +### Success Output: +``` +[INFO] Starting AITBC Development Environment... +[INFO] Starting incus containers... +[SUCCESS] Container aitbc started successfully +[SUCCESS] Container aitbc1 started successfully +[INFO] Starting AITBC systemd services on localhost... +[SUCCESS] Service aitbc-coordinator-api started successfully +[SUCCESS] Service aitbc-wallet-daemon started successfully +[INFO] Checking service status... +[SUCCESS] aitbc-coordinator-api: RUNNING +[SUCCESS] aitbc-wallet-daemon: RUNNING +[SUCCESS] AITBC Development Environment startup complete! +``` + +### Service Status: +``` +[INFO] Checking AITBC service ports... +[SUCCESS] Coordinator API (port 8001): RUNNING +[SUCCESS] Wallet Daemon (port 8002): RUNNING +[WARNING] Blockchain RPC (port 8003): NOT RUNNING +``` + +## πŸ› οΈ Troubleshooting + +### Common Issues: + +1. **Container not found:** + ``` + [ERROR] Container aitbc not found. Please create it first. + ``` + **Solution:** Create the incus containers first: + ```bash + incus launch images:ubuntu/22.04 aitbc + incus launch images:ubuntu/22.04 aitbc1 + ``` + +2. **Service not found:** + ``` + [WARNING] No AITBC services found on localhost + ``` + **Solution:** Install AITBC services or check if they're named correctly. + +3. **Port already in use:** + ``` + [WARNING] Service aitbc-coordinator-api is already running + ``` + **Solution:** This is normal - the script detects already running services. + +4. **Permission denied:** + ``` + [ERROR] Failed to start service aitbc-coordinator-api + ``` + **Solution:** Run with sudo or check user permissions. + +### Debug Commands: + +```bash +# Check all AITBC services +systemctl list-units | grep aitbc- + +# Check container status +incus list + +# View service logs +journalctl -f -u aitbc-coordinator-api + +# View container logs +incus exec aitbc -- journalctl -f -u aitbc-coordinator-api + +# Check port usage +netstat -tlnp | grep :800 +``` + +## πŸ”„ Workflow + +### Development Setup: +1. Create incus containers (if not exists) +2. Install AITBC services in containers +3. Install AITBC systemd services locally +4. Run `./scripts/start-aitbc-full.sh` + +### Daily Development: +1. `./scripts/start-aitbc-full.sh` - Start everything +2. Work on AITBC development +3. `./scripts/stop-aitbc-dev.sh` - Stop when done + +### Testing: +1. Start services with scripts +2. Test health endpoints +3. Check logs for issues +4. Stop services when finished + +## πŸ“š Additional Information + +- **Container IPs:** Scripts show container IP addresses for direct access +- **Health Checks:** Automatic health endpoint testing +- **Service Status:** Real-time status reporting +- **Error Handling:** Graceful error handling with informative messages + +## 🎯 Best Practices + +1. **Use the full script** for complete environment setup +2. **Check the output** for any warnings or errors +3. **Monitor logs** when troubleshooting issues +4. **Stop services** when not in use to conserve resources +5. **Run scripts from the project root** for proper path resolution diff --git a/scripts/check-aitbc-services.sh b/scripts/check-aitbc-services.sh new file mode 100755 index 00000000..422f7454 --- /dev/null +++ b/scripts/check-aitbc-services.sh @@ -0,0 +1,195 @@ +#!/bin/bash + +# AITBC Service Location Diagnostic Script +# Shows exactly where each AITBC service is running + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +print_container() { + echo -e "${CYAN}[CONTAINER]${NC} $1" +} + +print_local() { + echo -e "${CYAN}[LOCAL]${NC} $1" +} + +print_status "AITBC Service Location Diagnostic" + +# Get container IPs +containers=("aitbc" "aitbc1") +declare -A container_ips + +for container in "${containers[@]}"; do + if incus info "$container" >/dev/null 2>&1; then + if incus info "$container" | grep -q "Status: RUNNING"; then + container_ip=$(incus exec "$container" -- ip addr show eth0 2>/dev/null | grep "inet " | awk '{print $2}' | cut -d/ -f1 || echo "N/A") + container_ips["$container"]="$container_ip" + fi + fi +done + +# Check local services +print_local "Local AITBC Services:" +local_services=$(systemctl list-units --all | grep "aitbc-" | awk '{print $1}' | grep -v "not-found") + +if [ -n "$local_services" ]; then + for service in $local_services; do + service_name=$(echo "$service" | sed 's/\.service$//') + if systemctl is-active --quiet "$service_name" 2>/dev/null; then + # Get port if possible + port_info="" + case $service_name in + *coordinator-api*) port_info=" (port 8001)" ;; + *wallet*) port_info=" (port 8002)" ;; + *blockchain*) port_info=" (port 8003)" ;; + esac + print_success " βœ… $service_name: RUNNING$port_info" + else + print_error " ❌ $service_name: NOT RUNNING" + fi + done +else + print_warning " No AITBC services found locally" +fi + +echo "" + +# Check container services +for container in "${containers[@]}"; do + if incus info "$container" >/dev/null 2>&1; then + if incus info "$container" | grep -q "Status: RUNNING"; then + container_ip="${container_ips[$container]}" + print_container "Container $container (IP: $container_ip):" + + # Check common AITBC services in container + services=("aitbc-coordinator-api" "aitbc-wallet-daemon" "aitbc-blockchain-node") + + for service in "${services[@]}"; do + if incus exec "$container" -- systemctl list-unit-files 2>/dev/null | grep -q "^${service}.service"; then + if incus exec "$container" -- systemctl is-active --quiet "$service" 2>/dev/null; then + # Get port if possible + port_info="" + case $service in + *coordinator-api*) port_info=" (port 8001)" ;; + *wallet*) port_info=" (port 8002)" ;; + *blockchain*) port_info=" (port 8003)" ;; + esac + print_success " βœ… $service: RUNNING$port_info" + else + print_error " ❌ $service: NOT RUNNING" + fi + else + print_warning " ⚠️ $service: NOT INSTALLED" + fi + done + else + print_error "Container $container: NOT RUNNING" + fi + else + print_error "Container $container: NOT FOUND" + fi + echo "" +done + +# Port scan summary +print_status "Port Scan Summary:" +ports=("8001:Coordinator API" "8002:Wallet Daemon" "8003:Blockchain RPC" "8000:Coordinator API (alt)") + +for port_info in "${ports[@]}"; do + port=$(echo "$port_info" | cut -d: -f1) + service_name=$(echo "$port_info" | cut -d: -f2) + + if netstat -tlnp 2>/dev/null | grep -q ":$port "; then + process_info=$(netstat -tlnp 2>/dev/null | grep ":$port " | head -1) + pid=$(echo "$process_info" | awk '{print $7}' | cut -d/ -f1) + if [ -n "$pid" ] && [ "$pid" != "-" ]; then + print_success " βœ… Port $port ($service_name): LOCAL (PID $pid)" + else + print_success " βœ… Port $port ($service_name): LOCAL" + fi + else + # Check containers + found=false + for container in "${containers[@]}"; do + container_ip="${container_ips[$container]}" + if [ "$container_ip" != "N/A" ]; then + if timeout 2 bash -c "/dev/null; then + print_success " βœ… Port $port ($service_name): Container $container ($container_ip)" + found=true + break + fi + fi + done + + if [ "$found" = false ]; then + print_error " ❌ Port $port ($service_name): NOT ACCESSIBLE" + fi + fi +done + +echo "" +print_status "Health Check Summary:" +health_endpoints=( + "http://localhost:8001/health:Coordinator API" + "http://localhost:8002/health:Wallet Daemon" + "http://localhost:8003/health:Blockchain RPC" +) + +for endpoint_info in "${health_endpoints[@]}"; do + url=$(echo "$endpoint_info" | cut -d: -f1-3) + service_name=$(echo "$endpoint_info" | cut -d: -f4) + + if curl -s --max-time 3 "$url" >/dev/null 2>&1; then + print_success " βœ… $service_name: HEALTHY (LOCAL)" + else + # Check containers + found=false + for container in "${containers[@]}"; do + container_ip="${container_ips[$container]}" + if [ "$container_ip" != "N/A" ]; then + container_url="http://$container_ip:$(echo "$url" | cut -d: -f3)/health" + if curl -s --max-time 2 "$container_url" >/dev/null 2>&1; then + print_success " βœ… $service_name: HEALTHY (Container $container)" + found=true + break + fi + fi + done + + if [ "$found" = false ]; then + print_error " ❌ $service_name: NOT RESPONDING" + fi + fi +done + +echo "" +print_status "Quick Debug Commands:" +echo " - Check specific service: systemctl status " +echo " - Check container service: incus exec -- systemctl status " +echo " - View service logs: journalctl -f -u " +echo " - View container logs: incus exec -- journalctl -f -u " +echo " - Check port usage: netstat -tlnp | grep :800" diff --git a/scripts/debug-services.sh b/scripts/debug-services.sh new file mode 100755 index 00000000..d247c413 --- /dev/null +++ b/scripts/debug-services.sh @@ -0,0 +1,115 @@ +#!/bin/bash + +# Debug script to identify malformed service names + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +print_status() { + echo -e "${BLUE}[DEBUG]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +print_status "Debugging AITBC service names..." + +# Show raw systemctl output +print_status "Raw systemctl output for AITBC services:" +systemctl list-units --all | grep "aitbc-" | cat -A + +echo "" + +# Show each field separately +print_status "Analyzing service names field by field:" +systemctl list-units --all | grep "aitbc-" | while read -r line; do + echo "Raw line: '$line'" + + # Extract each field + unit=$(echo "$line" | awk '{print $1}') + load=$(echo "$line" | awk '{print $2}') + active=$(echo "$line" | awk '{print $3}') + sub=$(echo "$line" | awk '{print $4}') + description=$(echo "$line" | cut -d' ' -f5-) + + echo " Unit: '$unit'" + echo " Load: '$load'" + echo " Active: '$active'" + echo " Sub: '$sub'" + echo " Description: '$description'" + + # Check if unit name is valid + if [[ "$unit" =~ [^a-zA-Z0-9\-\._] ]]; then + print_error " ❌ Invalid characters in unit name!" + echo " ❌ Hex representation: $(echo -n "$unit" | od -c)" + else + print_success " βœ… Valid unit name" + fi + + echo "" +done + +# Check for any hidden characters +print_status "Checking for hidden characters in service names:" +systemctl list-units --all | grep "aitbc-" | awk '{print $2}' | grep "\.service$" | while read -r service; do + echo "Service: '$service'" + echo "Length: ${#service}" + echo "Hex dump:" + echo -n "$service" | od -c + echo "" +done + +# Show systemctl list-unit-files output +print_status "Checking systemctl list-unit-files:" +systemctl list-unit-files | grep "aitbc-" | cat -A + +# Check service files on disk +print_status "Checking service files in /etc/systemd/system/:" +if [ -d "/etc/systemd/system" ]; then + find /etc/systemd/system/ -name "*aitbc*" -type f | while read -r file; do + echo "Found: $file" + basename "$file" + echo "Hex: $(basename "$file" | od -c)" + echo "" + done +fi + +# Check service files in user directory +print_status "Checking service files in user directory:" +if [ -d "$HOME/.config/systemd/user" ]; then + find "$HOME/.config/systemd/user" -name "*aitbc*" -type f 2>/dev/null | while read -r file; do + echo "Found: $file" + basename "$file" + echo "Hex: $(basename "$file" | od -c)" + echo "" + done +fi + +# Check for any encoding issues +print_status "Checking locale and encoding:" +echo "Current locale: $LANG" +echo "System encoding: $(locale charmap)" +echo "" + +# Try to reload systemd daemon +print_status "Reloading systemd daemon to clear any cached issues:" +sudo systemctl daemon-reload +echo "Daemon reload completed" + +echo "" +print_status "Debug complete. Review the output above to identify the source of the malformed service name." diff --git a/scripts/start-aitbc-dev.sh b/scripts/start-aitbc-dev.sh new file mode 100755 index 00000000..e0f2be00 --- /dev/null +++ b/scripts/start-aitbc-dev.sh @@ -0,0 +1,398 @@ +#!/bin/bash + +# AITBC Development Environment Startup Script +# Starts incus containers and all AITBC services on localhost + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Function to check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Function to check if service is running +is_service_running() { + systemctl is-active --quiet "$1" 2>/dev/null +} + +# Function to check if port is in use +is_port_in_use() { + netstat -tlnp 2>/dev/null | grep -q ":$1 " +} + +# Function to check if service exists in container +service_exists_in_container() { + local container="$1" + local service="$2" + case $container in + "aitbc") + ssh aitbc-cascade "systemctl list-unit-files 2>/dev/null | grep -q '^${service}.service'" 2>/dev/null + ;; + "aitbc1") + ssh aitbc1-cascade "systemctl list-unit-files 2>/dev/null | grep -q '^${service}.service'" 2>/dev/null + ;; + *) + return 1 + ;; + esac +} + +# Function to check if service is running in container +is_service_running_in_container() { + local container="$1" + local service="$2" + case $container in + "aitbc") + ssh aitbc-cascade "systemctl is-active --quiet '$service' 2>/dev/null" 2>/dev/null + ;; + "aitbc1") + ssh aitbc1-cascade "systemctl is-active --quiet '$service' 2>/dev/null" 2>/dev/null + ;; + *) + return 1 + ;; + esac +} + +# Function to get container IP +get_container_ip() { + local container="$1" + case $container in + "aitbc") + ssh aitbc-cascade "hostname -I | awk '{print \$1}'" 2>/dev/null || echo "N/A" + ;; + "aitbc1") + ssh aitbc1-cascade "hostname -I | awk '{print \$1}'" 2>/dev/null || echo "N/A" + ;; + *) + echo "N/A" + ;; + esac +} + +print_status "Starting AITBC Development Environment..." + +# Check prerequisites +if ! command_exists incus; then + print_error "incus command not found. Please install incus first." + exit 1 +fi + +if ! command_exists systemctl; then + print_error "systemctl command not found. This script requires systemd." + exit 1 +fi + +# Step 1: Check remote containers via SSH +print_status "Checking remote containers via SSH..." + +containers=("aitbc" "aitbc1") +for container in "${containers[@]}"; do + print_status "Checking container: $container" + + case $container in + "aitbc") + if ssh aitbc-cascade "echo 'Container is accessible'" >/dev/null 2>&1; then + print_success "Container $container is accessible via SSH" + else + print_error "Container $container is not accessible via SSH" + exit 1 + fi + ;; + "aitbc1") + if ssh aitbc1-cascade "echo 'Container is accessible'" >/dev/null 2>&1; then + print_success "Container $container is accessible via SSH" + else + print_error "Container $container is not accessible via SSH" + exit 1 + fi + ;; + esac +done + +# Step 2: Wait for containers to be fully ready +print_status "Waiting for containers to be ready..." +sleep 5 + +# Step 3: Get container IPs for location detection +declare -A container_ips +for container in "${containers[@]}"; do + container_ip=$(get_container_ip "$container") + container_ips["$container"]="$container_ip" +done + +# Step 3: Start AITBC systemd services on localhost +print_status "Starting AITBC systemd services on localhost..." + +# Get all AITBC services (fixed to handle column alignment issues) +aitbc_services=$(systemctl list-units --all | grep "aitbc-" | awk '{print $2}' | grep "\.service$" | grep -v "not-found") + +# Filter out invalid service names +filtered_services="" +for service in $aitbc_services; do + # Skip invalid or malformed service names + if [[ "$service" =~ [^a-zA-Z0-9\-\._] ]]; then + print_warning "Skipping invalid service name: $service" + continue + fi + filtered_services="$filtered_services $service" +done +aitbc_services="$filtered_services" + +if [ -z "$aitbc_services" ]; then + print_warning "No AITBC services found on localhost" +else + print_status "Found AITBC services:" + echo "$aitbc_services" | sed 's/^/ - /' + + # Start each service + for service in $aitbc_services; do + service_name=$(echo "$service" | sed 's/\.service$//') + print_status "Starting service: $service_name" + + if is_service_running "$service_name"; then + print_warning "Service $service_name is already running" + else + if systemctl start "$service_name"; then + print_success "Service $service_name started successfully" + else + print_error "Failed to start service $service_name" + fi + fi + done +fi + +# Step 4: Wait for services to initialize +print_status "Waiting for services to initialize..." +sleep 10 + +# Step 6: Check service status with location information +print_status "Checking service status with location information..." + +# Check systemd services on localhost +if [ -n "$aitbc_services" ]; then + print_status "Local Systemd Services Status:" + for service in $aitbc_services; do + service_name=$(echo "$service" | sed 's/\.service$//') + if is_service_running "$service_name"; then + print_success "$service_name: RUNNING (LOCAL)" + else + print_error "$service_name: NOT RUNNING (LOCAL)" + fi + done +fi + +# Check services in containers +print_status "Container Services Status:" + +# Define services to check in containers +container_services=("aitbc-coordinator-api" "aitbc-wallet-daemon" "aitbc-blockchain-node-1" "aitbc-blockchain-node-2" "aitbc-exchange-api" "aitbc-explorer") + +for container in "${containers[@]}"; do + container_ip="${container_ips[$container]}" + print_status "Container $container (IP: $container_ip):" + + for service in "${container_services[@]}"; do + if service_exists_in_container "$container" "$service"; then + if is_service_running_in_container "$container" "$service"; then + print_success " $service: RUNNING (in $container)" + else + print_error " $service: NOT RUNNING (in $container)" + fi + else + print_warning " $service: NOT FOUND (in $container)" + fi + done +done + +# Check common AITBC ports with location detection +print_status "Checking AITBC service ports with location detection..." + +ports=( + "8000:Coordinator API" + "8001:Exchange API" + "8002:Blockchain Node" + "8003:Blockchain RPC" + "8080:Container Coordinator API" + "8081:Container Blockchain Node 1" + "8082:Container Exchange API" + "8083:Container Wallet Daemon" + "8084:Container Blockchain Node 2" + "8085:Container Explorer UI" + "8086:Container Marketplace" + "8087:Container Miner Dashboard" + "8088:Container Load Balancer" + "8089:Container Debug API" +) + +for port_info in "${ports[@]}"; do + port=$(echo "$port_info" | cut -d: -f1) + service_name=$(echo "$port_info" | cut -d: -f2) + + if is_port_in_use "$port"; then + # Try to determine which process is using the port + process_info=$(netstat -tlnp 2>/dev/null | grep ":$port " | head -1) + if [ -n "$process_info" ]; then + pid=$(echo "$process_info" | awk '{print $7}' | cut -d/ -f1) + if [ -n "$pid" ] && [ "$pid" != "-" ]; then + # Check if it's a local process + if ps -p "$pid" -o command= 2>/dev/null | grep -q "python.*uvicorn"; then + print_success "$service_name (port $port): RUNNING (LOCAL - PID $pid)" + else + print_success "$service_name (port $port): RUNNING (PID $pid)" + fi + else + print_success "$service_name (port $port): RUNNING" + fi + else + print_success "$service_name (port $port): RUNNING" + fi + else + # Check if service might be running in a container + found_in_container=false + for container in "${containers[@]}"; do + container_ip="${container_ips[$container]}" + if [ "$container_ip" != "N/A" ]; then + if timeout 3 bash -c "/dev/null; then + print_warning "$service_name (port $port): RUNNING (in container $container)" + found_in_container=true + break + fi + fi + done + + if [ "$found_in_container" = false ]; then + print_warning "$service_name (port $port): NOT RUNNING" + fi + fi +done + +# Step 7: Test health endpoints with location detection +print_status "Testing health endpoints with location detection..." + +health_endpoints=( + "http://localhost:8000/health:Coordinator API" + "http://localhost:8001/health:Exchange API" + "http://localhost:8003/health:Blockchain RPC" + "http://localhost:8004/health:Blockchain Node 2" + "http://localhost:8005/health:Blockchain RPC 2" + "http://localhost:8080/health:Container Coordinator API" + "http://localhost:8083/health:Container Wallet Daemon" +) + +for endpoint_info in "${health_endpoints[@]}"; do + url=$(echo "$endpoint_info" | cut -d: -f1-3) + service_name=$(echo "$endpoint_info" | cut -d: -f4) + + if curl -s --max-time 5 "$url" >/dev/null 2>&1; then + print_success "$service_name: HEALTHY (LOCAL)" + else + # Check if service is available in containers + found_in_container=false + for container in "${containers[@]}"; do + container_ip="${container_ips[$container]}" + if [ "$container_ip" != "N/A" ]; then + container_url="http://$container_ip:$(echo "$url" | cut -d: -f3)/health" + if curl -s --max-time 3 "$container_url" >/dev/null 2>&1; then + print_success "$service_name: HEALTHY (in $container)" + found_in_container=true + break + fi + fi + done + + if [ "$found_in_container" = false ]; then + print_warning "$service_name: NOT RESPONDING" + fi + fi +done + +# Step 7: Check remote container status +print_status "Checking remote container status..." +for container in "${containers[@]}"; do + container_ip="${container_ips[$container]}" + case $container in + "aitbc") + if ssh aitbc-cascade "echo 'Container is running'" >/dev/null 2>&1; then + print_success "Container $container: RUNNING (SSH accessible)" + print_status " IP: $container_ip" + print_status " Access: ssh aitbc-cascade" + else + print_error "Container $container: NOT ACCESSIBLE" + fi + ;; + "aitbc1") + if ssh aitbc1-cascade "echo 'Container is running'" >/dev/null 2>&1; then + print_success "Container $container: RUNNING (SSH accessible)" + print_status " IP: $container_ip" + print_status " Access: ssh aitbc1-cascade" + else + print_error "Container $container: NOT ACCESSIBLE" + fi + ;; + esac +done + +print_success "AITBC Development Environment startup complete!" +print_status "Summary:" +echo " - Incus containers: ${#containers[@]} started" +echo " - Systemd services: $(echo "$aitbc_services" | wc -l) found" +echo " - Check individual service logs with: journalctl -u " +echo " - Access services at their respective ports" +echo "" +print_status "Useful commands:" +echo " - Check all AITBC services: systemctl list-units | grep aitbc-" +echo " - Access aitbc container: ssh aitbc-cascade" +echo " - Access aitbc1 container: ssh aitbc1-cascade" +echo " - View local service logs: journalctl -f -u " +echo " - View container service logs: ssh aitbc-cascade 'journalctl -f -u '" +echo " - Check container services: ssh aitbc-cascade 'systemctl status '" +echo " - Check all services in aitbc: ssh aitbc-cascade 'systemctl list-units | grep aitbc-'" +echo " - Check all services in aitbc1: ssh aitbc1-cascade 'systemctl list-units | grep aitbc-'" +echo " - Stop all services: ./scripts/stop-aitbc-dev.sh" +echo "" +print_status "Debug specific issues:" +echo " - Debug aitbc coordinator: ssh aitbc-cascade 'systemctl status aitbc-coordinator-api'" +echo " - Debug aitbc1 coordinator: ssh aitbc1-cascade 'systemctl status aitbc-coordinator-api'" +echo " - Debug aitbc wallet: ssh aitbc-cascade 'systemctl status aitbc-wallet-daemon'" +echo " - Debug aitbc blockchain 1: ssh aitbc-cascade 'systemctl status aitbc-blockchain-node-1'" +echo " - Debug local blockchain 2: systemctl status aitbc-blockchain-node-2" +echo " - Debug aitbc exchange: ssh aitbc-cascade 'systemctl status aitbc-exchange-api'" +echo "" +print_status "Port Migration Commands:" +echo " - Update container coordinator to port 8080: ssh aitbc-cascade 'sudo systemctl edit aitbc-coordinator-api.service'" +echo " - Update container exchange to port 8082: ssh aitbc-cascade 'sudo systemctl edit aitbc-exchange-api.service'" +echo " - Update wallet daemon to port 8083: ssh aitbc-cascade 'sudo systemctl edit aitbc-wallet-daemon.service'" +echo " - Blockchain Node 2: Runs in container on port 8084 (not localhost)" +echo " - Blockchain Node 1: Use port 8081 (container)" +echo "" +print_status "Service URLs:" +echo " - Coordinator API: http://localhost:8000" +echo " - Exchange API: http://localhost:8001" +echo " - Blockchain RPC: http://localhost:8003" +echo " - Container Services: http://localhost:8080-8089" +echo " - Blockchain Node 2: http://localhost:8084 (container only)" diff --git a/scripts/start-aitbc-full.sh b/scripts/start-aitbc-full.sh new file mode 100755 index 00000000..be1199ac --- /dev/null +++ b/scripts/start-aitbc-full.sh @@ -0,0 +1,291 @@ +#!/bin/bash + +# AITBC Full Development Environment Startup Script +# Starts incus containers, services inside containers, and all AITBC services on localhost + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Function to check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Function to check if service is running +is_service_running() { + systemctl is-active --quiet "$1" 2>/dev/null +} + +# Function to check if port is in use +is_port_in_use() { + netstat -tlnp 2>/dev/null | grep -q ":$1 " +} + +print_status "Starting AITBC Full Development Environment..." + +# Check prerequisites +if ! command_exists incus; then + print_error "incus command not found. Please install incus first." + exit 1 +fi + +if ! command_exists systemctl; then + print_error "systemctl command not found. This script requires systemd." + exit 1 +fi + +# Step 1: Start incus containers +print_status "Starting incus containers..." + +containers=("aitbc" "aitbc1") +for container in "${containers[@]}"; do + print_status "Starting container: $container" + + if incus info "$container" >/dev/null 2>&1; then + if incus info "$container" | grep -q "Status: RUNNING"; then + print_warning "Container $container is already running" + else + if incus start "$container"; then + print_success "Container $container started successfully" + else + print_error "Failed to start container $container" + exit 1 + fi + fi + else + print_error "Container $container not found. Please create it first." + exit 1 + fi +done + +# Step 2: Wait for containers to be fully ready +print_status "Waiting for containers to be ready..." +sleep 10 + +# Step 3: Start services inside containers +print_status "Starting AITBC services inside containers..." + +container_services=( + "aitbc:aitbc-coordinator-api" + "aitbc:aitbc-wallet-daemon" + "aitbc:aitbc-blockchain-node" + "aitbc1:aitbc-coordinator-api" + "aitbc1:aitbc-wallet-daemon" + "aitbc1:aitbc-blockchain-node" +) + +for service_info in "${container_services[@]}"; do + container=$(echo "$service_info" | cut -d: -f1) + service=$(echo "$service_info" | cut -d: -f2) + + print_status "Starting $service in container $container" + + # Check if service exists in container + if incus exec "$container" -- systemctl list-unit-files | grep -q "$service.service"; then + # Start the service inside container + if incus exec "$container" -- systemctl start "$service"; then + print_success "$service started in $container" + else + print_warning "Failed to start $service in $container (may not be installed)" + fi + else + print_warning "$service not found in $container" + fi +done + +# Step 4: Start AITBC systemd services on localhost +print_status "Starting AITBC systemd services on localhost..." + +# Get all AITBC services +aitbc_services=$(systemctl list-units --all | grep "aitbc-" | awk '{print $1}' | grep -v "not-found") + +if [ -z "$aitbc_services" ]; then + print_warning "No AITBC services found on localhost" +else + print_status "Found AITBC services:" + echo "$aitbc_services" | sed 's/^/ - /' + + # Start each service + for service in $aitbc_services; do + service_name=$(echo "$service" | sed 's/\.service$//') + print_status "Starting service: $service_name" + + if is_service_running "$service_name"; then + print_warning "Service $service_name is already running" + else + if systemctl start "$service_name"; then + print_success "Service $service_name started successfully" + else + print_error "Failed to start service $service_name" + fi + fi + done +fi + +# Step 5: Wait for services to initialize +print_status "Waiting for services to initialize..." +sleep 15 + +# Step 6: Check service status +print_status "Checking service status..." + +# Check systemd services on localhost +if [ -n "$aitbc_services" ]; then + print_status "Local Systemd Services Status:" + for service in $aitbc_services; do + service_name=$(echo "$service" | sed 's/\.service$//') + if is_service_running "$service_name"; then + print_success "$service_name: RUNNING" + else + print_error "$service_name: NOT RUNNING" + fi + done +fi + +# Check services in containers +print_status "Container Services Status:" +for service_info in "${container_services[@]}"; do + container=$(echo "$service_info" | cut -d: -f1) + service=$(echo "$service_info" | cut -d: -f2) + + if incus exec "$container" -- systemctl is-active --quiet "$service" 2>/dev/null; then + print_success "$service in $container: RUNNING" + else + print_warning "$service in $container: NOT RUNNING" + fi +done + +# Check common AITBC ports +print_status "Checking AITBC service ports..." + +ports=( + "8001:Coordinator API" + "8002:Wallet Daemon" + "8003:Blockchain RPC" + "8000:Coordinator API (alt)" + "8081:Blockchain Node 1" + "8082:Blockchain Node 2" + "8006:Coordinator API (dev)" +) + +for port_info in "${ports[@]}"; do + port=$(echo "$port_info" | cut -d: -f1) + service_name=$(echo "$port_info" | cut -d: -f2) + + if is_port_in_use "$port"; then + print_success "$service_name (port $port): RUNNING" + else + print_warning "$service_name (port $port): NOT RUNNING" + fi +done + +# Step 7: Test health endpoints +print_status "Testing health endpoints..." + +health_endpoints=( + "http://localhost:8001/health:Coordinator API" + "http://localhost:8002/health:Wallet Daemon" + "http://localhost:8003/health:Blockchain RPC" +) + +for endpoint_info in "${health_endpoints[@]}"; do + url=$(echo "$endpoint_info" | cut -d: -f1-3) + service_name=$(echo "$endpoint_info" | cut -d: -f4) + + if curl -s --max-time 5 "$url" >/dev/null 2>&1; then + print_success "$service_name: HEALTHY" + else + print_warning "$service_name: NOT RESPONDING" + fi +done + +# Step 8: Container status and IPs +print_status "Container status and network information..." + +for container in "${containers[@]}"; do + if incus info "$container" | grep -q "Status: RUNNING"; then + print_success "Container $container: RUNNING" + + # Get container IP + container_ip=$(incus exec "$container" -- ip addr show eth0 2>/dev/null | grep "inet " | awk '{print $2}' | cut -d/ -f1 || echo "N/A") + if [ "$container_ip" != "N/A" ]; then + print_status " IP: $container_ip" + + # Test connectivity to container services + print_status " Testing container services:" + for service_info in "${container_services[@]}"; do + cont=$(echo "$service_info" | cut -d: -f1) + serv=$(echo "$service_info" | cut -d: -f2) + + if [ "$cont" = "$container" ]; then + case $serv in + "aitbc-coordinator-api") + if curl -s --max-time 3 "http://$container_ip:8001/health" >/dev/null 2>&1; then + print_success " Coordinator API: HEALTHY" + else + print_warning " Coordinator API: NOT RESPONDING" + fi + ;; + "aitbc-wallet-daemon") + if curl -s --max-time 3 "http://$container_ip:8002/health" >/dev/null 2>&1; then + print_success " Wallet Daemon: HEALTHY" + else + print_warning " Wallet Daemon: NOT RESPONDING" + fi + ;; + "aitbc-blockchain-node") + if curl -s --max-time 3 "http://$container_ip:8003/health" >/dev/null 2>&1; then + print_success " Blockchain Node: HEALTHY" + else + print_warning " Blockchain Node: NOT RESPONDING" + fi + ;; + esac + fi + done + fi + else + print_error "Container $container: NOT RUNNING" + fi +done + +print_success "AITBC Full Development Environment startup complete!" +print_status "Summary:" +echo " - Incus containers: ${#containers[@]} started" +echo " - Local systemd services: $(echo "$aitbc_services" | wc -l) found" +echo " - Container services: ${#container_services[@]} attempted" +echo "" +print_status "Useful commands:" +echo " - Check all AITBC services: systemctl list-units | grep aitbc-" +echo " - Check container status: incus list" +echo " - View service logs: journalctl -f -u aitbc-coordinator-api" +echo " - View container logs: incus exec aitbc -- journalctl -f -u aitbc-coordinator-api" +echo " - Stop all services: ./scripts/stop-aitbc-full.sh" +echo "" +print_status "Service URLs:" +echo " - Coordinator API: http://localhost:8001" +echo " - Wallet Daemon: http://localhost:8002" +echo " - Blockchain RPC: http://localhost:8003" diff --git a/scripts/stop-aitbc-dev.sh b/scripts/stop-aitbc-dev.sh new file mode 100755 index 00000000..641c7aa9 --- /dev/null +++ b/scripts/stop-aitbc-dev.sh @@ -0,0 +1,142 @@ +#!/bin/bash + +# AITBC Development Environment Stop Script +# Stops incus containers and all AITBC services on localhost + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' # No Color + +# Function to print colored output +print_status() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +# Function to check if command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +# Function to check if service is running +is_service_running() { + systemctl is-active --quiet "$1" 2>/dev/null +} + +print_status "Stopping AITBC Development Environment..." + +# Check prerequisites +if ! command_exists incus; then + print_error "incus command not found. Please install incus first." + exit 1 +fi + +if ! command_exists systemctl; then + print_error "systemctl command not found. This script requires systemd." + exit 1 +fi + +# Step 1: Stop AITBC systemd services on localhost +print_status "Stopping AITBC systemd services on localhost..." + +# Get all AITBC services +aitbc_services=$(systemctl list-units --all | grep "aitbc-" | awk '{print $1}' | grep -v "not-found") + +if [ -z "$aitbc_services" ]; then + print_warning "No AITBC services found on localhost" +else + print_status "Found AITBC services:" + echo "$aitbc_services" | sed 's/^/ - /' + + # Stop each service + for service in $aitbc_services; do + service_name=$(echo "$service" | sed 's/\.service$//') + print_status "Stopping service: $service_name" + + if is_service_running "$service_name"; then + if systemctl stop "$service_name"; then + print_success "Service $service_name stopped successfully" + else + print_error "Failed to stop service $service_name" + fi + else + print_warning "Service $service_name is already stopped" + fi + done +fi + +# Step 2: Stop incus containers +print_status "Stopping incus containers..." + +containers=("aitbc" "aitbc1") +for container in "${containers[@]}"; do + print_status "Stopping container: $container" + + if incus info "$container" >/dev/null 2>&1; then + # Check if container is running + if incus info "$container" | grep -q "Status: RUNNING"; then + if incus stop "$container"; then + print_success "Container $container stopped successfully" + else + print_error "Failed to stop container $container" + fi + else + print_warning "Container $container is already stopped" + fi + else + print_warning "Container $container not found" + fi +done + +# Step 3: Verify services are stopped +print_status "Verifying services are stopped..." + +# Check systemd services +if [ -n "$aitbc_services" ]; then + print_status "Systemd Services Status:" + for service in $aitbc_services; do + service_name=$(echo "$service" | sed 's/\.service$//') + if is_service_running "$service_name"; then + print_error "$service_name: STILL RUNNING" + else + print_success "$service_name: STOPPED" + fi + done +fi + +# Check containers +print_status "Container Status:" +for container in "${containers[@]}"; do + if incus info "$container" >/dev/null 2>&1; then + if incus info "$container" | grep -q "Status: RUNNING"; then + print_error "Container $container: STILL RUNNING" + else + print_success "Container $container: STOPPED" + fi + else + print_warning "Container $container: NOT FOUND" + fi +done + +print_success "AITBC Development Environment shutdown complete!" +print_status "Summary:" +echo " - Incus containers: ${#containers[@]} stopped" +echo " - Systemd services: $(echo "$aitbc_services" | wc -l) stopped" +echo "" +print_status "To start again: ./scripts/start-aitbc-dev.sh"