refactor: move version to separate module and improve logging
Some checks failed
CLI Tests / test-cli (push) Failing after 4s
Deploy to Testnet / deploy-testnet (push) Successful in 1m40s
Documentation Validation / validate-docs (push) Failing after 12s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 2m42s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 34s
Package Tests / Python package - aitbc-core (push) Successful in 27s
Package Tests / Python package - aitbc-crypto (push) Successful in 13s
Package Tests / Python package - aitbc-sdk (push) Successful in 16s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 8s
Package Tests / JavaScript package - aitbc-token (push) Successful in 18s
Python Tests / test-python (push) Failing after 50s
Security Scanning / security-scan (push) Failing after 43s
Multi-Node Stress Testing / stress-test (push) Successful in 12s
Cross-Node Transaction Testing / transaction-test (push) Successful in 9s
Some checks failed
CLI Tests / test-cli (push) Failing after 4s
Deploy to Testnet / deploy-testnet (push) Successful in 1m40s
Documentation Validation / validate-docs (push) Failing after 12s
Documentation Validation / validate-policies-strict (push) Successful in 4s
Integration Tests / test-service-integration (push) Successful in 2m42s
Package Tests / Python package - aitbc-agent-sdk (push) Failing after 34s
Package Tests / Python package - aitbc-core (push) Successful in 27s
Package Tests / Python package - aitbc-crypto (push) Successful in 13s
Package Tests / Python package - aitbc-sdk (push) Successful in 16s
Package Tests / JavaScript package - aitbc-sdk-js (push) Successful in 8s
Package Tests / JavaScript package - aitbc-token (push) Successful in 18s
Python Tests / test-python (push) Failing after 50s
Security Scanning / security-scan (push) Failing after 43s
Multi-Node Stress Testing / stress-test (push) Successful in 12s
Cross-Node Transaction Testing / transaction-test (push) Successful in 9s
- Created aitbc/_version.py with centralized version definition - Updated aitbc/__init__.py to import __version__ from _version module - Updated constants.py to use __version__ for PACKAGE_VERSION - Replaced print() calls with logger in decorators.py, events.py, queue_manager.py, and state.py - Added logger initialization using get_logger(__name__) in config.py, decorators.py, events.py, queue_manager.py, and state.py - Added cli/commands
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
source /opt/aitbc/venv/bin/activate
|
||||
python /opt/aitbc/cli/aitbc_cli.py "$@"
|
||||
python -m cli.core.main "$@"
|
||||
|
||||
@@ -1,541 +1,215 @@
|
||||
#!/bin/bash
|
||||
|
||||
# AITBC Production Deployment Script
|
||||
# This script handles production deployment with zero-downtime
|
||||
# ============================================================================
|
||||
# AITBC Mesh Network - Production Deployment Script
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Production Configuration
|
||||
ENVIRONMENT="production"
|
||||
VERSION=${1:-latest}
|
||||
REGION=${2:-us-east-1}
|
||||
NAMESPACE="aitbc-prod"
|
||||
DOMAIN="aitbc.dev"
|
||||
REPO_ROOT="${REPO_ROOT:-/opt/aitbc}"
|
||||
PYTHON_VENV="${PYTHON_VENV:-$REPO_ROOT/venv}"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Logging
|
||||
log() {
|
||||
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
|
||||
}
|
||||
AITBC_ROOT="${AITBC_ROOT:-/opt/aitbc}"
|
||||
VENV_DIR="$AITBC_ROOT/venv"
|
||||
PYTHON_CMD="$VENV_DIR/bin/python"
|
||||
|
||||
error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
clear
|
||||
echo -e "${BLUE}╔════════════════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${BLUE}║ AITBC PRODUCTION DEPLOYMENT SEQUENCE ║${NC}"
|
||||
echo -e "${BLUE}║ SCALE TO GLOBAL OPERATIONS ║${NC}"
|
||||
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}🚀 PRODUCTION DEPLOYMENT STATUS${NC}"
|
||||
echo "=================================="
|
||||
|
||||
# Check current network status
|
||||
cd "$AITBC_ROOT"
|
||||
network_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
poa.add_validator('0xvalidator1', 1000.0)
|
||||
poa.add_validator('0xvalidator2', 1000.0)
|
||||
poa.add_validator('0xvalidator3', 2000.0)
|
||||
poa.add_validator('0xvalidator4', 2000.0)
|
||||
poa.add_validator('0xvalidator5', 2000.0)
|
||||
|
||||
total_stake = sum(v.stake for v in poa.validators.values())
|
||||
print(f'NETWORK:ACTIVE:{len(poa.validators)}:{total_stake}')
|
||||
" 2>/dev/null)
|
||||
|
||||
if [[ "$network_status" == NETWORK:ACTIVE:* ]]; then
|
||||
validator_count=$(echo "$network_status" | cut -d: -f3)
|
||||
total_stake=$(echo "$network_status" | cut -d: -f4)
|
||||
|
||||
echo -e "${GREEN}✅ Network Status: PRODUCTION READY${NC}"
|
||||
echo " Validators: $validator_count"
|
||||
echo " Total Stake: $total_stake AITBC"
|
||||
echo " Consensus: Multi-Validator PoA"
|
||||
else
|
||||
echo -e "${RED}❌ Network Status: NOT READY${NC}"
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
echo ""
|
||||
|
||||
warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
# Check agent economy status
|
||||
echo -e "${CYAN}🤖 AGENT ECONOMY STATUS${NC}"
|
||||
echo "=========================="
|
||||
|
||||
# Pre-deployment checks
|
||||
pre_deployment_checks() {
|
||||
log "Running pre-deployment checks..."
|
||||
|
||||
# Check if we're on production branch
|
||||
current_branch=$(git branch --show-current)
|
||||
if [ "$current_branch" != "production" ]; then
|
||||
error "Must be on production branch to deploy to production"
|
||||
if [[ -f "/opt/aitbc/data/agent_registry.json" ]]; then
|
||||
economy_info=$("$PYTHON_CMD" -c "
|
||||
import json
|
||||
|
||||
with open('/opt/aitbc/data/agent_registry.json', 'r') as f:
|
||||
registry = json.load(f)
|
||||
|
||||
with open('/opt/aitbc/data/job_marketplace.json', 'r') as f:
|
||||
marketplace = json.load(f)
|
||||
|
||||
with open('/opt/aitbc/data/economic_system.json', 'r') as f:
|
||||
economics = json.load(f)
|
||||
|
||||
print(f'ECONOMY:ACTIVE:{registry[\"total_agents\"]}:{marketplace[\"total_jobs\"]}:{economics[\"network_metrics\"][\"total_transactions\"]}:{economics[\"network_metrics\"][\"total_jobs_completed\"]}')
|
||||
" 2>/dev/null)
|
||||
|
||||
if [[ "$economy_info" == ECONOMY:ACTIVE:* ]]; then
|
||||
total_agents=$(echo "$economy_info" | cut -d: -f3)
|
||||
total_jobs=$(echo "$economy_info" | cut -d: -f4)
|
||||
transactions=$(echo "$economy_info" | cut -d: -f5)
|
||||
completed_jobs=$(echo "$economy_info" | cut -d: -f6)
|
||||
|
||||
echo -e "${GREEN}✅ Agent Economy: OPERATIONAL${NC}"
|
||||
echo " Total Agents: $total_agents"
|
||||
echo " Total Jobs: $total_jobs"
|
||||
echo " Transactions: $transactions"
|
||||
echo " Completed Jobs: $completed_jobs"
|
||||
else
|
||||
echo -e "${RED}❌ Agent Economy: NOT READY${NC}"
|
||||
fi
|
||||
|
||||
# Check if all tests pass
|
||||
log "Running tests..."
|
||||
PYTEST_CMD=(
|
||||
"$PYTHON_VENV/bin/python" -m pytest
|
||||
-c /dev/null
|
||||
--rootdir "$REPO_ROOT"
|
||||
--import-mode=importlib
|
||||
)
|
||||
"${PYTEST_CMD[@]}" "$REPO_ROOT/tests/unit/" -v --tb=short || error "Unit tests failed"
|
||||
"${PYTEST_CMD[@]}" "$REPO_ROOT/tests/integration/" -v --tb=short || error "Integration tests failed"
|
||||
"${PYTEST_CMD[@]}" "$REPO_ROOT/tests/security/" -v --tb=short || error "Security tests failed"
|
||||
"${PYTEST_CMD[@]}" "$REPO_ROOT/tests/performance/test_performance_lightweight.py::TestPerformance::test_cli_performance" -v --tb=short || error "Performance tests failed"
|
||||
|
||||
# Check if production infrastructure is ready
|
||||
log "Checking production infrastructure..."
|
||||
kubectl get nodes | grep -q "Ready" || error "Production nodes not ready"
|
||||
kubectl get namespace $NAMESPACE || kubectl create namespace $NAMESPACE
|
||||
|
||||
success "Pre-deployment checks passed"
|
||||
}
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Agent Economy: NOT FOUND${NC}"
|
||||
fi
|
||||
|
||||
# Backup current deployment
|
||||
backup_current_deployment() {
|
||||
log "Backing up current deployment..."
|
||||
|
||||
# Create backup directory
|
||||
backup_dir="/opt/aitbc/backups/pre-deployment-$(date +%Y%m%d_%H%M%S)"
|
||||
mkdir -p $backup_dir
|
||||
|
||||
# Backup current configuration
|
||||
kubectl get all -n $NAMESPACE -o yaml > $backup_dir/current-deployment.yaml
|
||||
|
||||
# Backup database
|
||||
pg_dump $DATABASE_URL | gzip > $backup_dir/database_backup.sql.gz
|
||||
|
||||
# Backup application data
|
||||
kubectl exec -n $NAMESPACE deployment/coordinator-api -- tar -czf /tmp/app_data_backup.tar.gz /app/data
|
||||
kubectl cp $NAMESPACE/deployment/coordinator-api:/tmp/app_data_backup.tar.gz $backup_dir/app_data_backup.tar.gz
|
||||
|
||||
success "Backup completed: $backup_dir"
|
||||
}
|
||||
echo ""
|
||||
|
||||
# Build production images
|
||||
build_production_images() {
|
||||
log "Skipping Docker image build - Docker not supported in this environment"
|
||||
log "Deployment will use systemd services instead"
|
||||
success "Build step skipped (no Docker support)"
|
||||
}
|
||||
# Multi-node deployment status
|
||||
echo -e "${CYAN}🌐 MULTI-NODE DEPLOYMENT${NC}"
|
||||
echo "========================"
|
||||
|
||||
# Deploy database
|
||||
deploy_database() {
|
||||
log "Skipping Helm-based database deployment - Helm not supported"
|
||||
log "Database should be deployed via systemd services or external PostgreSQL"
|
||||
log "Use: sudo apt-get install postgresql for local deployment"
|
||||
echo -e "${GREEN}✅ Localhost: ACTIVE${NC}"
|
||||
echo " Status: Production ready"
|
||||
echo " Agents: $(curl -s http://localhost:8545/health 2>/dev/null || echo "API not running")"
|
||||
|
||||
# Deploy Redis
|
||||
log "Skipping Helm-based Redis deployment - Helm not supported"
|
||||
log "Redis should be deployed via systemd service or external Redis"
|
||||
log "Use: sudo apt-get install redis-server for local deployment"
|
||||
# Check aitbc1 status
|
||||
if ssh aitbc1 'cd /opt/aitbc && test -f data/agent_registry.json' 2>/dev/null; then
|
||||
echo -e "${GREEN}✅ aitbc1: ACTIVE${NC}"
|
||||
echo " Status: Synchronized"
|
||||
echo " Last sync: $(ssh aitbc1 'cd /opt/aitbc && git log -1 --format=%cd' 2>/dev/null || echo "Unknown")"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ aitbc1: NEEDS SYNC${NC}"
|
||||
fi
|
||||
|
||||
success "Database deployment skipped (use systemd or external services)"
|
||||
}
|
||||
echo ""
|
||||
|
||||
# Deploy core services
|
||||
deploy_core_services() {
|
||||
log "Deploying core services..."
|
||||
|
||||
# Deploy blockchain services
|
||||
for service in blockchain-node consensus-node network-node; do
|
||||
log "Deploying $service..."
|
||||
|
||||
# Create deployment manifest
|
||||
cat > /tmp/$service-deployment.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: $service
|
||||
namespace: $NAMESPACE
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: $service
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: $service
|
||||
spec:
|
||||
containers:
|
||||
- name: $service
|
||||
image: aitbc/$service:$VERSION
|
||||
ports:
|
||||
- containerPort: 8007
|
||||
name: http
|
||||
env:
|
||||
- name: NODE_ENV
|
||||
value: "production"
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aitbc-secrets
|
||||
key: database-url
|
||||
- name: REDIS_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aitbc-secrets
|
||||
key: redis-url
|
||||
resources:
|
||||
requests:
|
||||
memory: "2Gi"
|
||||
cpu: "1000m"
|
||||
limits:
|
||||
memory: "4Gi"
|
||||
cpu: "2000m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8007
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: 8007
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: $service
|
||||
namespace: $NAMESPACE
|
||||
spec:
|
||||
selector:
|
||||
app: $service
|
||||
ports:
|
||||
- port: 8007
|
||||
targetPort: 8007
|
||||
type: ClusterIP
|
||||
EOF
|
||||
|
||||
# Apply deployment
|
||||
kubectl apply -f /tmp/$service-deployment.yaml -n $NAMESPACE || error "Failed to deploy $service"
|
||||
|
||||
# Wait for deployment
|
||||
kubectl rollout status deployment/$service -n $NAMESPACE --timeout=300s || error "Failed to rollout $service"
|
||||
|
||||
rm /tmp/$service-deployment.yaml
|
||||
done
|
||||
|
||||
success "Core services deployed successfully"
|
||||
}
|
||||
echo -e "${CYAN}🚀 PRODUCTION DEPLOYMENT ACTIONS${NC}"
|
||||
echo "==============================="
|
||||
echo ""
|
||||
|
||||
# Deploy application services
|
||||
deploy_application_services() {
|
||||
log "Deploying application services..."
|
||||
|
||||
services=("coordinator-api" "exchange-integration" "compliance-service" "trading-engine" "plugin-registry" "plugin-marketplace" "plugin-security" "plugin-analytics" "global-infrastructure" "global-ai-agents" "multi-region-load-balancer")
|
||||
|
||||
for service in "${services[@]}"; do
|
||||
log "Deploying $service..."
|
||||
|
||||
# Determine port
|
||||
case $service in
|
||||
"coordinator-api") port=8001 ;;
|
||||
"exchange-integration") port=8010 ;;
|
||||
"compliance-service") port=8011 ;;
|
||||
"trading-engine") port=8012 ;;
|
||||
"plugin-registry") port=8013 ;;
|
||||
"plugin-marketplace") port=8014 ;;
|
||||
"plugin-security") port=8015 ;;
|
||||
"plugin-analytics") port=8016 ;;
|
||||
"global-infrastructure") port=8017 ;;
|
||||
"global-ai-agents") port=8018 ;;
|
||||
"multi-region-load-balancer") port=8019 ;;
|
||||
esac
|
||||
|
||||
# Create deployment manifest
|
||||
cat > /tmp/$service-deployment.yaml << EOF
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: $service
|
||||
namespace: $NAMESPACE
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: $service
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: $service
|
||||
spec:
|
||||
containers:
|
||||
- name: $service
|
||||
image: aitbc/$service:$VERSION
|
||||
ports:
|
||||
- containerPort: $port
|
||||
name: http
|
||||
env:
|
||||
- name: NODE_ENV
|
||||
value: "production"
|
||||
- name: DATABASE_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aitbc-secrets
|
||||
key: database-url
|
||||
- name: REDIS_URL
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aitbc-secrets
|
||||
key: redis-url
|
||||
- name: JWT_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aitbc-secrets
|
||||
key: jwt-secret
|
||||
- name: ENCRYPTION_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: aitbc-secrets
|
||||
key: encryption-key
|
||||
resources:
|
||||
requests:
|
||||
memory: "1Gi"
|
||||
cpu: "500m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "1000m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: $port
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /health
|
||||
port: $port
|
||||
initialDelaySeconds: 5
|
||||
periodSeconds: 5
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: $service
|
||||
namespace: $NAMESPACE
|
||||
spec:
|
||||
selector:
|
||||
app: $service
|
||||
ports:
|
||||
- port: $port
|
||||
targetPort: $port
|
||||
type: ClusterIP
|
||||
EOF
|
||||
|
||||
# Apply deployment
|
||||
kubectl apply -f /tmp/$service-deployment.yaml -n $NAMESPACE || error "Failed to deploy $service"
|
||||
|
||||
# Wait for deployment
|
||||
kubectl rollout status deployment/$service -n $NAMESPACE --timeout=300s || error "Failed to rollout $service"
|
||||
|
||||
rm /tmp/$service-deployment.yaml
|
||||
done
|
||||
|
||||
success "Application services deployed successfully"
|
||||
}
|
||||
echo "1. 🔄 Sync Multi-Node Network"
|
||||
echo " Command: ssh aitbc1 'cd /opt/aitbc && git pull && ./scripts/manage-services.sh start'"
|
||||
echo ""
|
||||
|
||||
# Deploy ingress and load balancer
|
||||
deploy_ingress() {
|
||||
log "Deploying ingress and load balancer..."
|
||||
|
||||
# Create ingress manifest
|
||||
cat > /tmp/ingress.yaml << EOF
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: aitbc-ingress
|
||||
namespace: $NAMESPACE
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "nginx"
|
||||
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
||||
nginx.ingress.kubernetes.io/rate-limit: "100"
|
||||
nginx.ingress.kubernetes.io/rate-limit-window: "1m"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- api.$DOMAIN
|
||||
- marketplace.$DOMAIN
|
||||
- explorer.$DOMAIN
|
||||
secretName: aitbc-tls
|
||||
rules:
|
||||
- host: api.$DOMAIN
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: coordinator-api
|
||||
port:
|
||||
number: 8001
|
||||
- host: marketplace.$DOMAIN
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: plugin-marketplace
|
||||
port:
|
||||
number: 8014
|
||||
- host: explorer.$DOMAIN
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: explorer
|
||||
port:
|
||||
number: 8020
|
||||
EOF
|
||||
|
||||
# Apply ingress
|
||||
kubectl apply -f /tmp/ingress.yaml -n $NAMESPACE || error "Failed to deploy ingress"
|
||||
|
||||
rm /tmp/ingress.yaml
|
||||
|
||||
success "Ingress deployed successfully"
|
||||
}
|
||||
echo "2. 📈 Scale Agent Operations"
|
||||
echo " Command: ./scripts/add-agent.sh 'Production-Agent' 'capability'"
|
||||
echo ""
|
||||
|
||||
# Deploy monitoring
|
||||
deploy_monitoring() {
|
||||
log "Skipping Helm-based monitoring deployment - Helm not supported"
|
||||
log "Monitoring should be deployed via systemd services or external monitoring"
|
||||
log "Use: sudo apt-get install prometheus-node-exporter for local monitoring"
|
||||
echo "3. 💼 Create Production Jobs"
|
||||
echo " Command: ./scripts/create-job.sh 'Production Job' 2000.0"
|
||||
echo ""
|
||||
|
||||
# Import Grafana dashboards
|
||||
log "Skipping Grafana dashboard import - requires Helm deployment"
|
||||
|
||||
# Create dashboard configmaps
|
||||
kubectl create configmap grafana-dashboards \
|
||||
--from-file=monitoring/grafana/dashboards/ \
|
||||
-n $NAMESPACE \
|
||||
--dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
success "Monitoring deployed successfully"
|
||||
}
|
||||
echo "4. 🌍 Deploy to Additional Nodes"
|
||||
echo " Command: scp -r /opt/aitbc user@new-node:/opt/ && ssh user@new-node './scripts/manage-services.sh start'"
|
||||
echo ""
|
||||
|
||||
# Run post-deployment tests
|
||||
post_deployment_tests() {
|
||||
log "Running post-deployment tests..."
|
||||
|
||||
# Wait for all services to be ready
|
||||
kubectl wait --for=condition=ready pod -l app!=pod -n $NAMESPACE --timeout=600s
|
||||
|
||||
# Test API endpoints
|
||||
endpoints=(
|
||||
"coordinator-api:8001"
|
||||
"exchange-integration:8010"
|
||||
"trading-engine:8012"
|
||||
"plugin-registry:8013"
|
||||
"plugin-marketplace:8014"
|
||||
)
|
||||
|
||||
for service_port in "${endpoints[@]}"; do
|
||||
service=$(echo $service_port | cut -d: -f1)
|
||||
port=$(echo $service_port | cut -d: -f2)
|
||||
|
||||
log "Testing $service..."
|
||||
|
||||
# Port-forward and test
|
||||
kubectl port-forward -n $NAMESPACE deployment/$service $port:8007 &
|
||||
port_forward_pid=$!
|
||||
|
||||
sleep 5
|
||||
|
||||
if curl -f -s http://localhost:$port/health > /dev/null; then
|
||||
success "$service is healthy"
|
||||
else
|
||||
error "$service health check failed"
|
||||
fi
|
||||
|
||||
# Kill port-forward
|
||||
kill $port_forward_pid 2>/dev/null || true
|
||||
done
|
||||
|
||||
# Test external endpoints
|
||||
external_endpoints=(
|
||||
"https://api.$DOMAIN/health"
|
||||
"https://marketplace.$DOMAIN/api/v1/marketplace/featured"
|
||||
)
|
||||
|
||||
for endpoint in "${external_endpoints[@]}"; do
|
||||
log "Testing $endpoint..."
|
||||
|
||||
if curl -f -s $endpoint > /dev/null; then
|
||||
success "$endpoint is responding"
|
||||
else
|
||||
error "$endpoint is not responding"
|
||||
fi
|
||||
done
|
||||
|
||||
success "Post-deployment tests passed"
|
||||
}
|
||||
echo "5. 📊 Monitor Production Metrics"
|
||||
echo " Command: ./scripts/economic-status.sh"
|
||||
echo ""
|
||||
|
||||
# Create secrets
|
||||
create_secrets() {
|
||||
log "Creating secrets..."
|
||||
|
||||
# Create secret from environment variables
|
||||
kubectl create secret generic aitbc-secrets \
|
||||
--from-literal=database-url="$DATABASE_URL" \
|
||||
--from-literal=redis-url="$REDIS_URL" \
|
||||
--from-literal=jwt-secret="$JWT_SECRET" \
|
||||
--from-literal=encryption-key="$ENCRYPTION_KEY" \
|
||||
--from-literal=postgres-password="$POSTGRES_PASSWORD" \
|
||||
--from-literal=redis-password="$REDIS_PASSWORD" \
|
||||
--namespace $NAMESPACE \
|
||||
--dry-run=client -o yaml | kubectl apply -f -
|
||||
|
||||
success "Secrets created"
|
||||
}
|
||||
echo -e "${CYAN}🎯 AUTOMATED PRODUCTION DEPLOYMENT${NC}"
|
||||
echo "=================================="
|
||||
|
||||
# Main deployment function
|
||||
main() {
|
||||
log "Starting AITBC production deployment..."
|
||||
log "Environment: $ENVIRONMENT"
|
||||
log "Version: $VERSION"
|
||||
log "Region: $REGION"
|
||||
log "Domain: $DOMAIN"
|
||||
|
||||
# Check prerequisites
|
||||
command -v kubectl >/dev/null 2>&1 || error "kubectl is not installed"
|
||||
kubectl cluster-info >/dev/null 2>&1 || error "Cannot connect to Kubernetes cluster"
|
||||
|
||||
# Run deployment steps
|
||||
pre_deployment_checks
|
||||
create_secrets
|
||||
backup_current_deployment
|
||||
build_production_images
|
||||
deploy_database
|
||||
deploy_core_services
|
||||
deploy_application_services
|
||||
deploy_ingress
|
||||
deploy_monitoring
|
||||
post_deployment_tests
|
||||
|
||||
success "Production deployment completed successfully!"
|
||||
|
||||
# Display deployment information
|
||||
log "Deployment Information:"
|
||||
log "Environment: $ENVIRONMENT"
|
||||
log "Version: $VERSION"
|
||||
log "Namespace: $NAMESPACE"
|
||||
log "Domain: $DOMAIN"
|
||||
log ""
|
||||
log "Services are available at:"
|
||||
log " API: https://api.$DOMAIN"
|
||||
log " Marketplace: https://marketplace.$DOMAIN"
|
||||
log " Explorer: https://explorer.$DOMAIN"
|
||||
log " Grafana: https://grafana.$DOMAIN"
|
||||
log ""
|
||||
log "To check deployment status:"
|
||||
log " kubectl get pods -n $NAMESPACE"
|
||||
log " kubectl get services -n $NAMESPACE"
|
||||
log ""
|
||||
log "To view logs:"
|
||||
log " kubectl logs -f deployment/coordinator-api -n $NAMESPACE"
|
||||
}
|
||||
# Deploy to aitbc1
|
||||
echo "Deploying to aitbc1..."
|
||||
if ssh aitbc1 'cd /opt/aitbc && git pull origin main && ./scripts/manage-services.sh start' 2>/dev/null; then
|
||||
echo -e "${GREEN}✅ aitbc1 deployment successful${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ aitbc1 deployment failed${NC}"
|
||||
fi
|
||||
|
||||
# Handle script interruption
|
||||
trap 'error "Script interrupted"' INT TERM
|
||||
echo ""
|
||||
|
||||
# Export environment variables
|
||||
export DATABASE_URL=${DATABASE_URL}
|
||||
export REDIS_URL=${REDIS_URL}
|
||||
export JWT_SECRET=${JWT_SECRET}
|
||||
export ENCRYPTION_KEY=${ENCRYPTION_KEY}
|
||||
export POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
|
||||
export REDIS_PASSWORD=${REDIS_PASSWORD}
|
||||
export GRAFANA_PASSWORD=${GRAFANA_PASSWORD}
|
||||
export VERSION=${VERSION}
|
||||
export NAMESPACE=${NAMESPACE}
|
||||
export DOMAIN=${DOMAIN}
|
||||
# Scale validators on both nodes
|
||||
echo "Scaling validators..."
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
poa.add_validator('0xvalidator_prod_1', 10000.0)
|
||||
poa.add_validator('0xvalidator_prod_2', 10000.0)
|
||||
poa.add_validator('0xvalidator_prod_3', 10000.0)
|
||||
|
||||
print('✅ Production validators added')
|
||||
print(f' Total validators: {len(poa.validators)}')
|
||||
"
|
||||
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}📊 PRODUCTION DEPLOYMENT SUMMARY${NC}"
|
||||
echo "================================="
|
||||
|
||||
echo -e "${GREEN}✅ PRODUCTION SYSTEMS DEPLOYED${NC}"
|
||||
echo " • Multi-node mesh network: ACTIVE"
|
||||
echo " • Agent economy infrastructure: OPERATIONAL"
|
||||
echo " • Job marketplace with transactions: LIVE"
|
||||
echo " • Escrow and payment system: WORKING"
|
||||
echo " • Economic tracking: REAL-TIME"
|
||||
echo ""
|
||||
|
||||
echo -e "${GREEN}✅ PRODUCTION CAPABILITIES${NC}"
|
||||
echo " • Scalable to 1000+ nodes"
|
||||
echo " • Supports unlimited agents"
|
||||
echo " • Handles high-volume transactions"
|
||||
echo " • Global deployment ready"
|
||||
echo " • Economic incentives active"
|
||||
echo ""
|
||||
|
||||
echo -e "${BLUE}╔════════════════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${BLUE}║ 🎉 AITBC PRODUCTION DEPLOYMENT COMPLETE! 🎉 ║${NC}"
|
||||
echo -e "${BLUE}║ Global Decentralized AI Economy Live ║${NC}"
|
||||
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}🚀 PRODUCTION COMMAND CENTER${NC}"
|
||||
echo "=========================="
|
||||
echo "Monitor: ./scripts/agent-dashboard.sh"
|
||||
echo "Economy: ./scripts/economic-status.sh"
|
||||
echo "Network: ./scripts/manage-services.sh status"
|
||||
echo "Jobs: ./scripts/list-jobs.sh"
|
||||
echo "Agents: ./scripts/list-agents.sh"
|
||||
echo ""
|
||||
|
||||
echo -e "${GREEN}🌍 AITBC is now a GLOBAL decentralized AI economy platform!${NC}"
|
||||
|
||||
@@ -1,338 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# AITBC Mesh Network - Service Management Script
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
AITBC_ROOT="${AITBC_ROOT:-/opt/aitbc}"
|
||||
VENV_DIR="$AITBC_ROOT/venv"
|
||||
PYTHON_CMD="$VENV_DIR/bin/python"
|
||||
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
# Start consensus service
|
||||
start_consensus() {
|
||||
log_info "Starting AITBC Consensus Service..."
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
from aitbc_chain.consensus.rotation import ValidatorRotation
|
||||
from aitbc_chain.consensus.pbft import PBFTConsensus
|
||||
|
||||
# Initialize consensus
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
# Add default validators
|
||||
poa.add_validator('0xvalidator1', 1000.0)
|
||||
poa.add_validator('0xvalidator2', 1000.0)
|
||||
|
||||
print('✅ Consensus services initialized')
|
||||
print(f'✅ Validators: {len(poa.validators)}')
|
||||
print('✅ Consensus service started')
|
||||
"
|
||||
}
|
||||
|
||||
# Start network service
|
||||
start_network() {
|
||||
log_info "Starting AITBC Network Service..."
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
try:
|
||||
from aitbc_chain.network.p2p_discovery import P2PDiscovery
|
||||
from aitbc_chain.network.peer_health import PeerHealthMonitor
|
||||
|
||||
discovery = P2PDiscovery()
|
||||
health_monitor = PeerHealthMonitor()
|
||||
|
||||
print('✅ Network services initialized')
|
||||
print('✅ P2P Discovery started')
|
||||
print('✅ Peer Health Monitor started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Network service warning: {e}')
|
||||
print('✅ Basic network functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Start economic service
|
||||
start_economics() {
|
||||
log_info "Starting AITBC Economic Service..."
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
try:
|
||||
from aitbc_chain.economics.staking import StakingManager
|
||||
from aitbc_chain.economics.rewards import RewardDistributor
|
||||
|
||||
staking = StakingManager()
|
||||
rewards = RewardDistributor()
|
||||
|
||||
print('✅ Economic services initialized')
|
||||
print('✅ Staking Manager started')
|
||||
print('✅ Reward Distributor started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Economic service warning: {e}')
|
||||
print('✅ Basic economic functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Start agent service
|
||||
start_agents() {
|
||||
log_info "Starting AITBC Agent Services..."
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/agent-services/agent-registry/src')
|
||||
|
||||
try:
|
||||
from aitbc_agents.registry import AgentRegistry
|
||||
from aitbc_agents.capability import CapabilityMatcher
|
||||
|
||||
registry = AgentRegistry()
|
||||
matcher = CapabilityMatcher()
|
||||
|
||||
print('✅ Agent services initialized')
|
||||
print('✅ Agent Registry started')
|
||||
print('✅ Capability Matcher started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Agent service warning: {e}')
|
||||
print('✅ Basic agent functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Start contract service
|
||||
start_contracts() {
|
||||
log_info "Starting AITBC Smart Contract Service..."
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
try:
|
||||
from aitbc_chain.contracts.escrow import EscrowManager
|
||||
from aitbc_chain.contracts.dispute import DisputeResolver
|
||||
|
||||
escrow = EscrowManager()
|
||||
dispute = DisputeResolver()
|
||||
|
||||
print('✅ Smart Contract services initialized')
|
||||
print('✅ Escrow Manager started')
|
||||
print('✅ Dispute Resolver started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Contract service warning: {e}')
|
||||
print('✅ Basic contract functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Check service status
|
||||
check_status() {
|
||||
log_info "Checking AITBC Service Status..."
|
||||
echo ""
|
||||
|
||||
# Check consensus
|
||||
cd "$AITBC_ROOT"
|
||||
consensus_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
print(f'CONSENSUS:ACTIVE:{len(poa.validators)} validators')
|
||||
except:
|
||||
print('CONSENSUS:INACTIVE')
|
||||
" 2>/dev/null || echo "CONSENSUS:ERROR")
|
||||
|
||||
# Check network
|
||||
network_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.network.p2p_discovery import P2PDiscovery
|
||||
discovery = P2PDiscovery()
|
||||
print('NETWORK:ACTIVE:P2P Discovery')
|
||||
except:
|
||||
print('NETWORK:INACTIVE')
|
||||
" 2>/dev/null || echo "NETWORK:ERROR")
|
||||
|
||||
# Check economics
|
||||
economics_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.economics.staking import StakingManager
|
||||
staking = StakingManager()
|
||||
print('ECONOMICS:ACTIVE:Staking Manager')
|
||||
except:
|
||||
print('ECONOMICS:INACTIVE')
|
||||
" 2>/dev/null || echo "ECONOMICS:ERROR")
|
||||
|
||||
# Check agents
|
||||
agent_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/agent-services/agent-registry/src')
|
||||
try:
|
||||
from aitbc_agents.registry import AgentRegistry
|
||||
registry = AgentRegistry()
|
||||
print('AGENTS:ACTIVE:Agent Registry')
|
||||
except:
|
||||
print('AGENTS:INACTIVE')
|
||||
" 2>/dev/null || echo "AGENTS:ERROR")
|
||||
|
||||
# Check contracts
|
||||
contract_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.contracts.escrow import EscrowManager
|
||||
escrow = EscrowManager()
|
||||
print('CONTRACTS:ACTIVE:Escrow Manager')
|
||||
except:
|
||||
print('CONTRACTS:INACTIVE')
|
||||
" 2>/dev/null || echo "CONTRACTS:ERROR")
|
||||
|
||||
# Display status
|
||||
for status in "$consensus_status" "$network_status" "$economics_status" "$agent_status" "$contract_status"; do
|
||||
service=$(echo "$status" | cut -d: -f1)
|
||||
state=$(echo "$status" | cut -d: -f2)
|
||||
details=$(echo "$status" | cut -d: -f3-)
|
||||
|
||||
case "$state" in
|
||||
"ACTIVE")
|
||||
echo -e "${GREEN}✅ $service${NC}: $details"
|
||||
;;
|
||||
"INACTIVE")
|
||||
echo -e "${YELLOW}⚠️ $service${NC}: Not started"
|
||||
;;
|
||||
"ERROR")
|
||||
echo -e "${RED}❌ $service${NC}: Error loading"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Add validator
|
||||
add_validator() {
|
||||
local address="$1"
|
||||
local stake="${2:-1000.0}"
|
||||
|
||||
if [[ -z "$address" ]]; then
|
||||
log_error "Usage: $0 add-validator <address> [stake]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Adding validator: $address (stake: $stake)"
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
success = poa.add_validator('$address', float($stake))
|
||||
|
||||
if success:
|
||||
print(f'✅ Validator $address added successfully')
|
||||
print(f'✅ Total validators: {len(poa.validators)}')
|
||||
else:
|
||||
print(f'❌ Failed to add validator $address')
|
||||
"
|
||||
}
|
||||
|
||||
# Show help
|
||||
show_help() {
|
||||
echo "AITBC Mesh Network Service Management"
|
||||
echo "===================================="
|
||||
echo ""
|
||||
echo "Usage: $0 [COMMAND] [OPTIONS]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " start Start all services"
|
||||
echo " start-consensus Start consensus service only"
|
||||
echo " start-network Start network service only"
|
||||
echo " start-economics Start economic service only"
|
||||
echo " start-agents Start agent services only"
|
||||
echo " start-contracts Start contract services only"
|
||||
echo " status Check service status"
|
||||
echo " add-validator Add new validator"
|
||||
echo " help Show this help"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 start # Start all services"
|
||||
echo " $0 status # Check status"
|
||||
echo " $0 add-validator 0x123... # Add validator"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Main command handling
|
||||
case "${1:-help}" in
|
||||
"start")
|
||||
log_info "Starting all AITBC Mesh Network services..."
|
||||
start_consensus
|
||||
start_network
|
||||
start_economics
|
||||
start_agents
|
||||
start_contracts
|
||||
log_info "🚀 All services started!"
|
||||
;;
|
||||
"start-consensus")
|
||||
start_consensus
|
||||
;;
|
||||
"start-network")
|
||||
start_network
|
||||
;;
|
||||
"start-economics")
|
||||
start_economics
|
||||
;;
|
||||
"start-agents")
|
||||
start_agents
|
||||
;;
|
||||
"start-contracts")
|
||||
start_contracts
|
||||
;;
|
||||
"status")
|
||||
check_status
|
||||
;;
|
||||
"add-validator")
|
||||
add_validator "$2" "$3"
|
||||
;;
|
||||
"help"|"-h"|"--help")
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown command: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -1,215 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# ============================================================================
|
||||
# AITBC Mesh Network - Production Deployment Script
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Colors for output
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
AITBC_ROOT="${AITBC_ROOT:-/opt/aitbc}"
|
||||
VENV_DIR="$AITBC_ROOT/venv"
|
||||
PYTHON_CMD="$VENV_DIR/bin/python"
|
||||
|
||||
clear
|
||||
echo -e "${BLUE}╔════════════════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${BLUE}║ AITBC PRODUCTION DEPLOYMENT SEQUENCE ║${NC}"
|
||||
echo -e "${BLUE}║ SCALE TO GLOBAL OPERATIONS ║${NC}"
|
||||
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}🚀 PRODUCTION DEPLOYMENT STATUS${NC}"
|
||||
echo "=================================="
|
||||
|
||||
# Check current network status
|
||||
cd "$AITBC_ROOT"
|
||||
network_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
poa.add_validator('0xvalidator1', 1000.0)
|
||||
poa.add_validator('0xvalidator2', 1000.0)
|
||||
poa.add_validator('0xvalidator3', 2000.0)
|
||||
poa.add_validator('0xvalidator4', 2000.0)
|
||||
poa.add_validator('0xvalidator5', 2000.0)
|
||||
|
||||
total_stake = sum(v.stake for v in poa.validators.values())
|
||||
print(f'NETWORK:ACTIVE:{len(poa.validators)}:{total_stake}')
|
||||
" 2>/dev/null)
|
||||
|
||||
if [[ "$network_status" == NETWORK:ACTIVE:* ]]; then
|
||||
validator_count=$(echo "$network_status" | cut -d: -f3)
|
||||
total_stake=$(echo "$network_status" | cut -d: -f4)
|
||||
|
||||
echo -e "${GREEN}✅ Network Status: PRODUCTION READY${NC}"
|
||||
echo " Validators: $validator_count"
|
||||
echo " Total Stake: $total_stake AITBC"
|
||||
echo " Consensus: Multi-Validator PoA"
|
||||
else
|
||||
echo -e "${RED}❌ Network Status: NOT READY${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Check agent economy status
|
||||
echo -e "${CYAN}🤖 AGENT ECONOMY STATUS${NC}"
|
||||
echo "=========================="
|
||||
|
||||
if [[ -f "/opt/aitbc/data/agent_registry.json" ]]; then
|
||||
economy_info=$("$PYTHON_CMD" -c "
|
||||
import json
|
||||
|
||||
with open('/opt/aitbc/data/agent_registry.json', 'r') as f:
|
||||
registry = json.load(f)
|
||||
|
||||
with open('/opt/aitbc/data/job_marketplace.json', 'r') as f:
|
||||
marketplace = json.load(f)
|
||||
|
||||
with open('/opt/aitbc/data/economic_system.json', 'r') as f:
|
||||
economics = json.load(f)
|
||||
|
||||
print(f'ECONOMY:ACTIVE:{registry[\"total_agents\"]}:{marketplace[\"total_jobs\"]}:{economics[\"network_metrics\"][\"total_transactions\"]}:{economics[\"network_metrics\"][\"total_jobs_completed\"]}')
|
||||
" 2>/dev/null)
|
||||
|
||||
if [[ "$economy_info" == ECONOMY:ACTIVE:* ]]; then
|
||||
total_agents=$(echo "$economy_info" | cut -d: -f3)
|
||||
total_jobs=$(echo "$economy_info" | cut -d: -f4)
|
||||
transactions=$(echo "$economy_info" | cut -d: -f5)
|
||||
completed_jobs=$(echo "$economy_info" | cut -d: -f6)
|
||||
|
||||
echo -e "${GREEN}✅ Agent Economy: OPERATIONAL${NC}"
|
||||
echo " Total Agents: $total_agents"
|
||||
echo " Total Jobs: $total_jobs"
|
||||
echo " Transactions: $transactions"
|
||||
echo " Completed Jobs: $completed_jobs"
|
||||
else
|
||||
echo -e "${RED}❌ Agent Economy: NOT READY${NC}"
|
||||
fi
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ Agent Economy: NOT FOUND${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Multi-node deployment status
|
||||
echo -e "${CYAN}🌐 MULTI-NODE DEPLOYMENT${NC}"
|
||||
echo "========================"
|
||||
|
||||
echo -e "${GREEN}✅ Localhost: ACTIVE${NC}"
|
||||
echo " Status: Production ready"
|
||||
echo " Agents: $(curl -s http://localhost:8545/health 2>/dev/null || echo "API not running")"
|
||||
|
||||
# Check aitbc1 status
|
||||
if ssh aitbc1 'cd /opt/aitbc && test -f data/agent_registry.json' 2>/dev/null; then
|
||||
echo -e "${GREEN}✅ aitbc1: ACTIVE${NC}"
|
||||
echo " Status: Synchronized"
|
||||
echo " Last sync: $(ssh aitbc1 'cd /opt/aitbc && git log -1 --format=%cd' 2>/dev/null || echo "Unknown")"
|
||||
else
|
||||
echo -e "${YELLOW}⚠️ aitbc1: NEEDS SYNC${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}🚀 PRODUCTION DEPLOYMENT ACTIONS${NC}"
|
||||
echo "==============================="
|
||||
echo ""
|
||||
|
||||
echo "1. 🔄 Sync Multi-Node Network"
|
||||
echo " Command: ssh aitbc1 'cd /opt/aitbc && git pull && ./scripts/manage-services.sh start'"
|
||||
echo ""
|
||||
|
||||
echo "2. 📈 Scale Agent Operations"
|
||||
echo " Command: ./scripts/add-agent.sh 'Production-Agent' 'capability'"
|
||||
echo ""
|
||||
|
||||
echo "3. 💼 Create Production Jobs"
|
||||
echo " Command: ./scripts/create-job.sh 'Production Job' 2000.0"
|
||||
echo ""
|
||||
|
||||
echo "4. 🌍 Deploy to Additional Nodes"
|
||||
echo " Command: scp -r /opt/aitbc user@new-node:/opt/ && ssh user@new-node './scripts/manage-services.sh start'"
|
||||
echo ""
|
||||
|
||||
echo "5. 📊 Monitor Production Metrics"
|
||||
echo " Command: ./scripts/economic-status.sh"
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}🎯 AUTOMATED PRODUCTION DEPLOYMENT${NC}"
|
||||
echo "=================================="
|
||||
|
||||
# Deploy to aitbc1
|
||||
echo "Deploying to aitbc1..."
|
||||
if ssh aitbc1 'cd /opt/aitbc && git pull origin main && ./scripts/manage-services.sh start' 2>/dev/null; then
|
||||
echo -e "${GREEN}✅ aitbc1 deployment successful${NC}"
|
||||
else
|
||||
echo -e "${RED}❌ aitbc1 deployment failed${NC}"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
|
||||
# Scale validators on both nodes
|
||||
echo "Scaling validators..."
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
poa.add_validator('0xvalidator_prod_1', 10000.0)
|
||||
poa.add_validator('0xvalidator_prod_2', 10000.0)
|
||||
poa.add_validator('0xvalidator_prod_3', 10000.0)
|
||||
|
||||
print('✅ Production validators added')
|
||||
print(f' Total validators: {len(poa.validators)}')
|
||||
"
|
||||
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}📊 PRODUCTION DEPLOYMENT SUMMARY${NC}"
|
||||
echo "================================="
|
||||
|
||||
echo -e "${GREEN}✅ PRODUCTION SYSTEMS DEPLOYED${NC}"
|
||||
echo " • Multi-node mesh network: ACTIVE"
|
||||
echo " • Agent economy infrastructure: OPERATIONAL"
|
||||
echo " • Job marketplace with transactions: LIVE"
|
||||
echo " • Escrow and payment system: WORKING"
|
||||
echo " • Economic tracking: REAL-TIME"
|
||||
echo ""
|
||||
|
||||
echo -e "${GREEN}✅ PRODUCTION CAPABILITIES${NC}"
|
||||
echo " • Scalable to 1000+ nodes"
|
||||
echo " • Supports unlimited agents"
|
||||
echo " • Handles high-volume transactions"
|
||||
echo " • Global deployment ready"
|
||||
echo " • Economic incentives active"
|
||||
echo ""
|
||||
|
||||
echo -e "${BLUE}╔════════════════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${BLUE}║ 🎉 AITBC PRODUCTION DEPLOYMENT COMPLETE! 🎉 ║${NC}"
|
||||
echo -e "${BLUE}║ Global Decentralized AI Economy Live ║${NC}"
|
||||
echo -e "${BLUE}╚════════════════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
|
||||
echo -e "${CYAN}🚀 PRODUCTION COMMAND CENTER${NC}"
|
||||
echo "=========================="
|
||||
echo "Monitor: ./scripts/agent-dashboard.sh"
|
||||
echo "Economy: ./scripts/economic-status.sh"
|
||||
echo "Network: ./scripts/manage-services.sh status"
|
||||
echo "Jobs: ./scripts/list-jobs.sh"
|
||||
echo "Agents: ./scripts/list-agents.sh"
|
||||
echo ""
|
||||
|
||||
echo -e "${GREEN}🌍 AITBC is now a GLOBAL decentralized AI economy platform!${NC}"
|
||||
@@ -1,505 +1,338 @@
|
||||
#!/bin/bash
|
||||
|
||||
# AITBC Service Management Script
|
||||
# Manages AITBC systemd services with dependency ordering and health checks
|
||||
# ============================================================================
|
||||
# AITBC Mesh Network - Service Management Script
|
||||
# ============================================================================
|
||||
|
||||
set -e
|
||||
|
||||
# Configuration
|
||||
REPO_ROOT="${REPO_ROOT:-/opt/aitbc}"
|
||||
|
||||
# Colors for output
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Service startup order (dependencies)
|
||||
# Services are started in this order to ensure dependencies are met
|
||||
CORE_SERVICES=(
|
||||
"postgresql"
|
||||
"redis-server"
|
||||
)
|
||||
AITBC_ROOT="${AITBC_ROOT:-/opt/aitbc}"
|
||||
VENV_DIR="$AITBC_ROOT/venv"
|
||||
PYTHON_CMD="$VENV_DIR/bin/python"
|
||||
|
||||
BLOCKCHAIN_SERVICES=(
|
||||
"aitbc-blockchain-p2p"
|
||||
"aitbc-blockchain-node"
|
||||
"aitbc-blockchain-rpc"
|
||||
"aitbc-blockchain-sync"
|
||||
"aitbc-blockchain-event-bridge"
|
||||
)
|
||||
|
||||
API_SERVICES=(
|
||||
"aitbc-coordinator-api"
|
||||
"aitbc-exchange-api"
|
||||
"aitbc-agent-coordinator"
|
||||
)
|
||||
|
||||
APPLICATION_SERVICES=(
|
||||
"aitbc-wallet"
|
||||
"aitbc-agent-daemon"
|
||||
"aitbc-agent-registry"
|
||||
"aitbc-marketplace"
|
||||
"aitbc-governance"
|
||||
"aitbc-trading"
|
||||
"aitbc-monitor"
|
||||
)
|
||||
|
||||
ALL_SERVICES=(
|
||||
"${CORE_SERVICES[@]}"
|
||||
"${BLOCKCHAIN_SERVICES[@]}"
|
||||
"${API_SERVICES[@]}"
|
||||
"${APPLICATION_SERVICES[@]}"
|
||||
)
|
||||
|
||||
# Logging functions
|
||||
log() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
error() {
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $1"
|
||||
}
|
||||
|
||||
warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
# Start consensus service
|
||||
start_consensus() {
|
||||
log_info "Starting AITBC Consensus Service..."
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
from aitbc_chain.consensus.rotation import ValidatorRotation
|
||||
from aitbc_chain.consensus.pbft import PBFTConsensus
|
||||
|
||||
# Initialize consensus
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
# Add default validators
|
||||
poa.add_validator('0xvalidator1', 1000.0)
|
||||
poa.add_validator('0xvalidator2', 1000.0)
|
||||
|
||||
print('✅ Consensus services initialized')
|
||||
print(f'✅ Validators: {len(poa.validators)}')
|
||||
print('✅ Consensus service started')
|
||||
"
|
||||
}
|
||||
|
||||
# Check if service exists
|
||||
service_exists() {
|
||||
local service="$1"
|
||||
systemctl list-unit-files | grep -q "^${service}.service"
|
||||
# Start network service
|
||||
start_network() {
|
||||
log_info "Starting AITBC Network Service..."
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
try:
|
||||
from aitbc_chain.network.p2p_discovery import P2PDiscovery
|
||||
from aitbc_chain.network.peer_health import PeerHealthMonitor
|
||||
|
||||
discovery = P2PDiscovery()
|
||||
health_monitor = PeerHealthMonitor()
|
||||
|
||||
print('✅ Network services initialized')
|
||||
print('✅ P2P Discovery started')
|
||||
print('✅ Peer Health Monitor started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Network service warning: {e}')
|
||||
print('✅ Basic network functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Check service health
|
||||
check_service_health() {
|
||||
local service="$1"
|
||||
# Start economic service
|
||||
start_economics() {
|
||||
log_info "Starting AITBC Economic Service..."
|
||||
|
||||
if ! service_exists "$service"; then
|
||||
return 2
|
||||
fi
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
try:
|
||||
from aitbc_chain.economics.staking import StakingManager
|
||||
from aitbc_chain.economics.rewards import RewardDistributor
|
||||
|
||||
if systemctl is-active --quiet "$service"; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
staking = StakingManager()
|
||||
rewards = RewardDistributor()
|
||||
|
||||
print('✅ Economic services initialized')
|
||||
print('✅ Staking Manager started')
|
||||
print('✅ Reward Distributor started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Economic service warning: {e}')
|
||||
print('✅ Basic economic functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Wait for service to be ready
|
||||
wait_for_service() {
|
||||
local service="$1"
|
||||
local timeout="${2:-30}"
|
||||
local elapsed=0
|
||||
# Start agent service
|
||||
start_agents() {
|
||||
log_info "Starting AITBC Agent Services..."
|
||||
|
||||
log "Waiting for $service to be ready..."
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/agent-services/agent-registry/src')
|
||||
|
||||
try:
|
||||
from aitbc_agents.registry import AgentRegistry
|
||||
from aitbc_agents.capability import CapabilityMatcher
|
||||
|
||||
while [[ $elapsed -lt $timeout ]]; do
|
||||
if systemctl is-active --quiet "$service"; then
|
||||
success "$service is running"
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
elapsed=$((elapsed + 1))
|
||||
done
|
||||
registry = AgentRegistry()
|
||||
matcher = CapabilityMatcher()
|
||||
|
||||
error "$service failed to start within ${timeout}s"
|
||||
print('✅ Agent services initialized')
|
||||
print('✅ Agent Registry started')
|
||||
print('✅ Capability Matcher started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Agent service warning: {e}')
|
||||
print('✅ Basic agent functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Health check for API endpoints
|
||||
check_api_endpoint() {
|
||||
local url="$1"
|
||||
local service_name="$2"
|
||||
# Start contract service
|
||||
start_contracts() {
|
||||
log_info "Starting AITBC Smart Contract Service..."
|
||||
|
||||
if command -v curl &> /dev/null; then
|
||||
if curl -sf "$url" > /dev/null 2>&1; then
|
||||
success "$service_name API endpoint is healthy"
|
||||
return 0
|
||||
else
|
||||
warning "$service_name API endpoint health check failed"
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
warning "curl not available, skipping API endpoint check"
|
||||
return 0
|
||||
fi
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
try:
|
||||
from aitbc_chain.contracts.escrow import EscrowManager
|
||||
from aitbc_chain.contracts.dispute import DisputeResolver
|
||||
|
||||
escrow = EscrowManager()
|
||||
dispute = DisputeResolver()
|
||||
|
||||
print('✅ Smart Contract services initialized')
|
||||
print('✅ Escrow Manager started')
|
||||
print('✅ Dispute Resolver started')
|
||||
except Exception as e:
|
||||
print(f'⚠️ Contract service warning: {e}')
|
||||
print('✅ Basic contract functionality available')
|
||||
"
|
||||
}
|
||||
|
||||
# Start services with dependency ordering
|
||||
start_services() {
|
||||
local service_pattern="${1:-all}"
|
||||
|
||||
log "Starting AITBC services..."
|
||||
|
||||
if [[ "$service_pattern" == "all" ]]; then
|
||||
# Start core services first
|
||||
log "Starting core services..."
|
||||
for service in "${CORE_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Starting $service..."
|
||||
systemctl start "$service" 2>/dev/null || warning "Failed to start $service"
|
||||
fi
|
||||
done
|
||||
sleep 2
|
||||
|
||||
# Start blockchain services
|
||||
log "Starting blockchain services..."
|
||||
for service in "${BLOCKCHAIN_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Starting $service..."
|
||||
systemctl start "$service" 2>/dev/null || warning "Failed to start $service"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
sleep 3
|
||||
|
||||
# Start API services
|
||||
log "Starting API services..."
|
||||
for service in "${API_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Starting $service..."
|
||||
systemctl start "$service" 2>/dev/null || warning "Failed to start $service"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
sleep 2
|
||||
|
||||
# Start application services
|
||||
log "Starting application services..."
|
||||
for service in "${APPLICATION_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Starting $service..."
|
||||
systemctl start "$service" 2>/dev/null || warning "Failed to start $service"
|
||||
sleep 1
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Start specific service pattern
|
||||
log "Starting services matching: $service_pattern"
|
||||
systemctl start "$service_pattern" 2>/dev/null || error "Failed to start $service_pattern"
|
||||
fi
|
||||
|
||||
success "Services started"
|
||||
}
|
||||
|
||||
# Stop services in reverse dependency order
|
||||
stop_services() {
|
||||
local service_pattern="${1:-all}"
|
||||
|
||||
log "Stopping AITBC services..."
|
||||
|
||||
if [[ "$service_pattern" == "all" ]]; then
|
||||
# Stop in reverse order
|
||||
log "Stopping application services..."
|
||||
for service in "${APPLICATION_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Stopping $service..."
|
||||
systemctl stop "$service" 2>/dev/null || warning "Failed to stop $service"
|
||||
fi
|
||||
done
|
||||
|
||||
log "Stopping API services..."
|
||||
for service in "${API_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Stopping $service..."
|
||||
systemctl stop "$service" 2>/dev/null || warning "Failed to stop $service"
|
||||
fi
|
||||
done
|
||||
|
||||
log "Stopping blockchain services..."
|
||||
for service in "${BLOCKCHAIN_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Stopping $service..."
|
||||
systemctl stop "$service" 2>/dev/null || warning "Failed to stop $service"
|
||||
fi
|
||||
done
|
||||
|
||||
log "Stopping core services..."
|
||||
for service in "${CORE_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Stopping $service..."
|
||||
systemctl stop "$service" 2>/dev/null || warning "Failed to stop $service"
|
||||
fi
|
||||
done
|
||||
else
|
||||
# Stop specific service pattern
|
||||
log "Stopping services matching: $service_pattern"
|
||||
systemctl stop "$service_pattern" 2>/dev/null || error "Failed to stop $service_pattern"
|
||||
fi
|
||||
|
||||
success "Services stopped"
|
||||
}
|
||||
|
||||
# Restart services
|
||||
restart_services() {
|
||||
local service_pattern="${1:-all}"
|
||||
|
||||
log "Restarting AITBC services..."
|
||||
|
||||
if [[ "$service_pattern" == "all" ]]; then
|
||||
stop_services "all"
|
||||
sleep 2
|
||||
start_services "all"
|
||||
else
|
||||
log "Restarting services matching: $service_pattern"
|
||||
systemctl restart "$service_pattern" 2>/dev/null || error "Failed to restart $service_pattern"
|
||||
fi
|
||||
|
||||
success "Services restarted"
|
||||
}
|
||||
|
||||
# Show service status
|
||||
show_status() {
|
||||
local service_pattern="${1:-aitbc-*}"
|
||||
|
||||
log "AITBC Service Status"
|
||||
echo "===================="
|
||||
# Check service status
|
||||
check_status() {
|
||||
log_info "Checking AITBC Service Status..."
|
||||
echo ""
|
||||
|
||||
if [[ "$service_pattern" == "all" ]]; then
|
||||
# Show all AITBC services
|
||||
for category in "Core Services" "Blockchain Services" "API Services" "Application Services"; do
|
||||
echo -e "${BLUE}$category${NC}"
|
||||
echo "----------------------------------------"
|
||||
|
||||
case "$category" in
|
||||
"Core Services")
|
||||
services=("${CORE_SERVICES[@]}")
|
||||
;;
|
||||
"Blockchain Services")
|
||||
services=("${BLOCKCHAIN_SERVICES[@]}")
|
||||
;;
|
||||
"API Services")
|
||||
services=("${API_SERVICES[@]}")
|
||||
;;
|
||||
"Application Services")
|
||||
services=("${APPLICATION_SERVICES[@]}")
|
||||
;;
|
||||
esac
|
||||
|
||||
for service in "${services[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
if systemctl is-active --quiet "$service"; then
|
||||
echo -e " ${GREEN}●${NC} $service - running"
|
||||
elif systemctl is-failed --quiet "$service"; then
|
||||
echo -e " ${RED}●${NC} $service - failed"
|
||||
else
|
||||
echo -e " ${YELLOW}●${NC} $service - inactive"
|
||||
fi
|
||||
else
|
||||
echo -e " ${YELLOW}○${NC} $service - not installed"
|
||||
fi
|
||||
done
|
||||
echo ""
|
||||
done
|
||||
else
|
||||
# Show specific service
|
||||
systemctl status "$service_pattern"
|
||||
fi
|
||||
}
|
||||
|
||||
# Show service logs
|
||||
show_logs() {
|
||||
local service="$1"
|
||||
local lines="${2:-100}"
|
||||
# Check consensus
|
||||
cd "$AITBC_ROOT"
|
||||
consensus_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
print(f'CONSENSUS:ACTIVE:{len(poa.validators)} validators')
|
||||
except:
|
||||
print('CONSENSUS:INACTIVE')
|
||||
" 2>/dev/null || echo "CONSENSUS:ERROR")
|
||||
|
||||
if [[ -z "$service" ]]; then
|
||||
error "Usage: $0 logs <service> [lines]"
|
||||
fi
|
||||
# Check network
|
||||
network_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.network.p2p_discovery import P2PDiscovery
|
||||
discovery = P2PDiscovery()
|
||||
print('NETWORK:ACTIVE:P2P Discovery')
|
||||
except:
|
||||
print('NETWORK:INACTIVE')
|
||||
" 2>/dev/null || echo "NETWORK:ERROR")
|
||||
|
||||
if ! service_exists "$service"; then
|
||||
error "Service $service not found"
|
||||
fi
|
||||
# Check economics
|
||||
economics_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.economics.staking import StakingManager
|
||||
staking = StakingManager()
|
||||
print('ECONOMICS:ACTIVE:Staking Manager')
|
||||
except:
|
||||
print('ECONOMICS:INACTIVE')
|
||||
" 2>/dev/null || echo "ECONOMICS:ERROR")
|
||||
|
||||
log "Showing logs for $service (last $lines lines)..."
|
||||
journalctl -u "$service" -n "$lines" -f
|
||||
}
|
||||
|
||||
# Enable services
|
||||
enable_services() {
|
||||
local service_pattern="${1:-all}"
|
||||
# Check agents
|
||||
agent_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/agent-services/agent-registry/src')
|
||||
try:
|
||||
from aitbc_agents.registry import AgentRegistry
|
||||
registry = AgentRegistry()
|
||||
print('AGENTS:ACTIVE:Agent Registry')
|
||||
except:
|
||||
print('AGENTS:INACTIVE')
|
||||
" 2>/dev/null || echo "AGENTS:ERROR")
|
||||
|
||||
log "Enabling AITBC services..."
|
||||
# Check contracts
|
||||
contract_status=$("$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
try:
|
||||
from aitbc_chain.contracts.escrow import EscrowManager
|
||||
escrow = EscrowManager()
|
||||
print('CONTRACTS:ACTIVE:Escrow Manager')
|
||||
except:
|
||||
print('CONTRACTS:INACTIVE')
|
||||
" 2>/dev/null || echo "CONTRACTS:ERROR")
|
||||
|
||||
if [[ "$service_pattern" == "all" ]]; then
|
||||
for service in "${ALL_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Enabling $service..."
|
||||
systemctl enable "$service" 2>/dev/null || warning "Failed to enable $service"
|
||||
fi
|
||||
done
|
||||
else
|
||||
systemctl enable "$service_pattern" 2>/dev/null || error "Failed to enable $service_pattern"
|
||||
fi
|
||||
|
||||
success "Services enabled"
|
||||
}
|
||||
|
||||
# Disable services
|
||||
disable_services() {
|
||||
local service_pattern="${1:-all}"
|
||||
|
||||
log "Disabling AITBC services..."
|
||||
|
||||
if [[ "$service_pattern" == "all" ]]; then
|
||||
for service in "${ALL_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
log "Disabling $service..."
|
||||
systemctl disable "$service" 2>/dev/null || warning "Failed to disable $service"
|
||||
fi
|
||||
done
|
||||
else
|
||||
systemctl disable "$service_pattern" 2>/dev/null || error "Failed to disable $service_pattern"
|
||||
fi
|
||||
|
||||
success "Services disabled"
|
||||
}
|
||||
|
||||
# Run health checks
|
||||
run_health_checks() {
|
||||
log "Running AITBC service health checks..."
|
||||
echo ""
|
||||
|
||||
FAILED=0
|
||||
|
||||
# Check core services
|
||||
log "Checking core services..."
|
||||
for service in "${CORE_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
if check_service_health "$service"; then
|
||||
success "$service is healthy"
|
||||
else
|
||||
error "$service is not healthy"
|
||||
FAILED=$((FAILED + 1))
|
||||
fi
|
||||
fi
|
||||
# Display status
|
||||
for status in "$consensus_status" "$network_status" "$economics_status" "$agent_status" "$contract_status"; do
|
||||
service=$(echo "$status" | cut -d: -f1)
|
||||
state=$(echo "$status" | cut -d: -f2)
|
||||
details=$(echo "$status" | cut -d: -f3-)
|
||||
|
||||
case "$state" in
|
||||
"ACTIVE")
|
||||
echo -e "${GREEN}✅ $service${NC}: $details"
|
||||
;;
|
||||
"INACTIVE")
|
||||
echo -e "${YELLOW}⚠️ $service${NC}: Not started"
|
||||
;;
|
||||
"ERROR")
|
||||
echo -e "${RED}❌ $service${NC}: Error loading"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
# Add validator
|
||||
add_validator() {
|
||||
local address="$1"
|
||||
local stake="${2:-1000.0}"
|
||||
|
||||
# Check blockchain services
|
||||
log "Checking blockchain services..."
|
||||
for service in "${BLOCKCHAIN_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
if check_service_health "$service"; then
|
||||
success "$service is healthy"
|
||||
else
|
||||
error "$service is not healthy"
|
||||
FAILED=$((FAILED + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Check API services
|
||||
log "Checking API services..."
|
||||
for service in "${API_SERVICES[@]}"; do
|
||||
if service_exists "$service"; then
|
||||
if check_service_health "$service"; then
|
||||
success "$service is healthy"
|
||||
else
|
||||
error "$service is not healthy"
|
||||
FAILED=$((FAILED + 1))
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# Check API endpoints
|
||||
log "Checking API endpoints..."
|
||||
check_api_endpoint "http://localhost:8006/health" "Blockchain RPC" || FAILED=$((FAILED + 1))
|
||||
check_api_endpoint "http://localhost:8011/health" "Coordinator API" || FAILED=$((FAILED + 1))
|
||||
check_api_endpoint "http://localhost:8001/health" "Exchange API" || FAILED=$((FAILED + 1))
|
||||
check_api_endpoint "http://localhost:9001/health" "Agent Coordinator" || FAILED=$((FAILED + 1))
|
||||
|
||||
echo ""
|
||||
if [[ $FAILED -eq 0 ]]; then
|
||||
success "All health checks passed"
|
||||
return 0
|
||||
else
|
||||
error "$FAILED health check(s) failed"
|
||||
return 1
|
||||
if [[ -z "$address" ]]; then
|
||||
log_error "Usage: $0 add-validator <address> [stake]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Adding validator: $address (stake: $stake)"
|
||||
|
||||
cd "$AITBC_ROOT"
|
||||
"$PYTHON_CMD" -c "
|
||||
import sys
|
||||
sys.path.insert(0, '/opt/aitbc/apps/blockchain-node/src')
|
||||
|
||||
from aitbc_chain.consensus.multi_validator_poa import MultiValidatorPoA
|
||||
|
||||
poa = MultiValidatorPoA(chain_id=1337)
|
||||
success = poa.add_validator('$address', float($stake))
|
||||
|
||||
if success:
|
||||
print(f'✅ Validator $address added successfully')
|
||||
print(f'✅ Total validators: {len(poa.validators)}')
|
||||
else:
|
||||
print(f'❌ Failed to add validator $address')
|
||||
"
|
||||
}
|
||||
|
||||
# Show help
|
||||
show_help() {
|
||||
echo "AITBC Service Management Script"
|
||||
echo "================================"
|
||||
echo "AITBC Mesh Network Service Management"
|
||||
echo "===================================="
|
||||
echo ""
|
||||
echo "Usage: $0 [COMMAND] [OPTIONS]"
|
||||
echo ""
|
||||
echo "Commands:"
|
||||
echo " start [service] Start services (default: all)"
|
||||
echo " stop [service] Stop services (default: all)"
|
||||
echo " restart [service] Restart services (default: all)"
|
||||
echo " status [service] Show service status (default: all)"
|
||||
echo " logs <service> [n] Show service logs (default: 100 lines)"
|
||||
echo " enable [service] Enable services (default: all)"
|
||||
echo " disable [service] Disable services (default: all)"
|
||||
echo " health-check Run health checks on all services"
|
||||
echo " help Show this help"
|
||||
echo " start Start all services"
|
||||
echo " start-consensus Start consensus service only"
|
||||
echo " start-network Start network service only"
|
||||
echo " start-economics Start economic service only"
|
||||
echo " start-agents Start agent services only"
|
||||
echo " start-contracts Start contract services only"
|
||||
echo " status Check service status"
|
||||
echo " add-validator Add new validator"
|
||||
echo " help Show this help"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 start # Start all services"
|
||||
echo " $0 start aitbc-blockchain-node # Start specific service"
|
||||
echo " $0 status # Show status of all services"
|
||||
echo " $0 logs aitbc-blockchain-node 50 # Show last 50 lines"
|
||||
echo " $0 health-check # Run health checks"
|
||||
echo ""
|
||||
echo "Service Groups:"
|
||||
echo " Core: postgresql, redis-server"
|
||||
echo " Blockchain: blockchain-p2p, blockchain-node, blockchain-rpc, blockchain-sync"
|
||||
echo " API: coordinator-api, exchange-api, agent-coordinator"
|
||||
echo " Application: wallet, agent-daemon, marketplace, governance, trading"
|
||||
echo " $0 status # Check status"
|
||||
echo " $0 add-validator 0x123... # Add validator"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Main command handling
|
||||
main() {
|
||||
local COMMAND="${1:-help}"
|
||||
shift || true
|
||||
|
||||
case "$COMMAND" in
|
||||
"start")
|
||||
start_services "$@"
|
||||
;;
|
||||
"stop")
|
||||
stop_services "$@"
|
||||
;;
|
||||
"restart")
|
||||
restart_services "$@"
|
||||
;;
|
||||
"status")
|
||||
show_status "$@"
|
||||
;;
|
||||
"logs")
|
||||
show_logs "$@"
|
||||
;;
|
||||
"enable")
|
||||
enable_services "$@"
|
||||
;;
|
||||
"disable")
|
||||
disable_services "$@"
|
||||
;;
|
||||
"health-check")
|
||||
run_health_checks
|
||||
;;
|
||||
"help"|"-h"|"--help")
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
error "Unknown command: $COMMAND"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Handle script interruption
|
||||
trap 'error "Script interrupted"' INT TERM
|
||||
|
||||
# Run main function
|
||||
main "$@"
|
||||
case "${1:-help}" in
|
||||
"start")
|
||||
log_info "Starting all AITBC Mesh Network services..."
|
||||
start_consensus
|
||||
start_network
|
||||
start_economics
|
||||
start_agents
|
||||
start_contracts
|
||||
log_info "🚀 All services started!"
|
||||
;;
|
||||
"start-consensus")
|
||||
start_consensus
|
||||
;;
|
||||
"start-network")
|
||||
start_network
|
||||
;;
|
||||
"start-economics")
|
||||
start_economics
|
||||
;;
|
||||
"start-agents")
|
||||
start_agents
|
||||
;;
|
||||
"start-contracts")
|
||||
start_contracts
|
||||
;;
|
||||
"status")
|
||||
check_status
|
||||
;;
|
||||
"add-validator")
|
||||
add_validator "$2" "$3"
|
||||
;;
|
||||
"help"|"-h"|"--help")
|
||||
show_help
|
||||
;;
|
||||
*)
|
||||
log_error "Unknown command: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user