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
This commit is contained in:
oib
2026-03-06 10:25:57 +01:00
parent 1511e7e7f5
commit a302da73a9
14 changed files with 1754 additions and 110 deletions

203
scripts/README.md Normal file
View File

@@ -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

195
scripts/check-aitbc-services.sh Executable file
View File

@@ -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/tcp/$container_ip/$port" 2>/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 <service-name>"
echo " - Check container service: incus exec <container> -- systemctl status <service-name>"
echo " - View service logs: journalctl -f -u <service-name>"
echo " - View container logs: incus exec <container> -- journalctl -f -u <service-name>"
echo " - Check port usage: netstat -tlnp | grep :800"

115
scripts/debug-services.sh Executable file
View File

@@ -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."

398
scripts/start-aitbc-dev.sh Executable file
View File

@@ -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/tcp/$container_ip/$port" 2>/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 <service-name>"
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 <service-name>"
echo " - View container service logs: ssh aitbc-cascade 'journalctl -f -u <service-name>'"
echo " - Check container services: ssh aitbc-cascade 'systemctl status <service-name>'"
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)"

291
scripts/start-aitbc-full.sh Executable file
View File

@@ -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"

142
scripts/stop-aitbc-dev.sh Executable file
View File

@@ -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"