Compare commits

...

4 Commits

Author SHA1 Message Date
aitbc1
e9f4193f7a chore: add missing aitbc-core package directory
Some checks failed
package-tests / test-python-packages (map[name:aitbc-agent-sdk path:packages/py/aitbc-agent-sdk python_version:3.13]) (push) Failing after 23s
package-tests / test-python-packages (map[name:aitbc-core path:packages/py/aitbc-core python_version:3.13]) (push) Successful in 11s
package-tests / test-python-packages (map[name:aitbc-crypto path:packages/py/aitbc-crypto python_version:3.13]) (push) Successful in 10s
package-tests / test-python-packages (map[name:aitbc-sdk path:packages/py/aitbc-sdk python_version:3.13]) (push) Successful in 10s
package-tests / test-javascript-packages (map[name:aitbc-sdk node_version:24 path:packages/js/aitbc-sdk]) (push) Successful in 20s
package-tests / cross-language-compatibility (push) Has been skipped
package-tests / package-integration-tests (push) Has been skipped
integration-tests / test-service-integration (push) Successful in 1m29s
python-tests / test-specific (push) Has been skipped
python-tests / test (push) Successful in 31s
systemd-sync / sync-systemd (push) Successful in 2s
security-scanning / audit (push) Successful in 1m32s
Documentation Validation / validate-docs (push) Successful in 6m4s
2026-03-28 10:18:29 +01:00
aitbc1
1d7efb241d chore: update minimum Python version to 3.13.5
- Update prerequisites check in setup.sh
- Update documentation in SETUP.md
2026-03-28 09:55:01 +01:00
aitbc1
1402f2b784 feat: add automated setup script for new hosts
- Add setup.sh that handles complete AITBC installation
- Creates virtual environments and installs dependencies
- Installs systemd services with fallback manual startup
- Adds health check and management scripts
- Include comprehensive SETUP.md documentation
2026-03-28 09:53:09 +01:00
aitbc1
76965a5d42 chore: update wallet service to use venv python and add requirements.txt 2026-03-28 09:48:27 +01:00
5 changed files with 468 additions and 1 deletions

121
SETUP.md Normal file
View File

@@ -0,0 +1,121 @@
# AITBC Setup Guide
## Quick Setup (New Host)
Run this single command on any new host to install AITBC:
```bash
sudo bash <(curl -sSL https://raw.githubusercontent.com/oib/aitbc/main/setup.sh)
```
Or clone and run manually:
```bash
sudo git clone https://gitea.bubuit.net/oib/aitbc.git /opt/aitbc
cd /opt/aitbc
sudo chmod +x setup.sh
sudo ./setup.sh
```
## What the Setup Script Does
1. **Prerequisites Check**
- Verifies Python 3.13.5+, pip3, git, systemd
- Checks for root privileges
2. **Repository Setup**
- Clones AITBC repository to `/opt/aitbc`
- Handles multiple repository URLs for reliability
3. **Virtual Environments**
- Creates Python venvs for each service
- Installs dependencies from `requirements.txt` when available
- Falls back to core dependencies if requirements missing
4. **Systemd Services**
- Installs service files to `/etc/systemd/system/`
- Enables auto-start on boot
- Provides fallback manual startup
5. **Service Management**
- Creates `/opt/aitbc/start-services.sh` for manual control
- Creates `/opt/aitbc/health-check.sh` for monitoring
- Sets up logging to `/var/log/aitbc-*.log`
## Service Endpoints
| Service | Port | Health Endpoint |
|---------|------|----------------|
| Wallet API | 8003 | `http://localhost:8003/health` |
| Exchange API | 8001 | `http://localhost:8001/api/health` |
| Coordinator API | 8000 | `http://localhost:8000/health` |
| Blockchain RPC | 8545 | `http://localhost:8545` |
## Management Commands
```bash
# Check service health
/opt/aitbc/health-check.sh
# Restart all services
/opt/aitbc/start-services.sh
# View logs
tail -f /var/log/aitbc-wallet.log
tail -f /var/log/aitbc-coordinator.log
tail -f /var/log/aitbc-exchange.log
# Systemd control
systemctl status aitbc-wallet
systemctl restart aitbc-coordinator-api
systemctl stop aitbc-exchange-api
```
## Troubleshooting
### Services Not Starting
1. Check logs: `tail -f /var/log/aitbc-*.log`
2. Verify ports: `netstat -tlnp | grep ':800'`
3. Check processes: `ps aux | grep python`
### Missing Dependencies
The setup script handles missing `requirements.txt` files by installing core dependencies:
- fastapi
- uvicorn
- pydantic
- httpx
- python-dotenv
### Port Conflicts
Services use these default ports. If conflicts exist:
1. Kill conflicting processes: `kill <pid>`
2. Modify service files to use different ports
3. Restart services
## Development Mode
For development with manual control:
```bash
cd /opt/aitbc/apps/wallet
source .venv/bin/activate
python simple_daemon.py
cd /opt/aitbc/apps/exchange
source .venv/bin/activate
python simple_exchange_api.py
cd /opt/aitbc/apps/coordinator-api/src
source ../.venv/bin/activate
python -m uvicorn app.main:app --host 0.0.0.0 --port 8000
```
## Production Considerations
For production deployment:
1. Configure proper environment variables
2. Set up reverse proxy (nginx)
3. Configure SSL certificates
4. Set up log rotation
5. Configure monitoring and alerts
6. Use proper database setup (PostgreSQL/Redis)

View File

@@ -0,0 +1,10 @@
fastapi>=0.111.0
uvicorn[standard]>=0.30.0
pydantic>=2.7.0
pydantic-settings>=2.2.1
sqlalchemy[asyncio]>=2.0.47
aiosqlite>=0.20.0
sqlmodel>=0.0.16
httpx>=0.27.0
python-dotenv>=1.0.1
asyncpg>=0.29.0

View File

@@ -0,0 +1,11 @@
"""
AITBC Core Utilities
"""
from . import logging
__all__ = ["logging"]
from . import logging
__all__ = ["logging"]

325
setup.sh Executable file
View File

@@ -0,0 +1,325 @@
#!/bin/bash
# AITBC Local Setup Script
# Sets up AITBC services on a new host with systemd
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
# Logging function
log() {
echo -e "${BLUE}[$(date +'%Y-%m-%d %H:%M:%S')]${NC} $1"
}
error() {
echo -e "${RED}[ERROR]${NC} $1"
exit 1
}
success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
# Check if running as root
check_root() {
if [ "$EUID" -ne 0 ]; then
error "This script must be run as root (use sudo)"
fi
}
# Check prerequisites
check_prerequisites() {
log "Checking prerequisites..."
# Check if required tools are installed
command -v python3 >/dev/null 2>&1 || error "Python 3 is not installed"
command -v pip3 >/dev/null 2>&1 || error "pip3 is not installed"
command -v git >/dev/null 2>&1 || error "git is not installed"
command -v systemctl >/dev/null 2>&1 || error "systemctl is not available"
# Check Python version
python_version=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')")
if [ "$(printf '%s\n' "3.13.5" "$python_version" | sort -V | head -n1)" != "3.13.5" ]; then
error "Python 3.13.5+ is required, found $python_version"
fi
success "Prerequisites check passed"
}
# Clone repository
clone_repo() {
log "Cloning AITBC repository..."
# Remove existing installation if present
if [ -d "/opt/aitbc" ]; then
warning "Removing existing /opt/aitbc"
rm -rf /opt/aitbc
fi
# Clone repository
cd /opt
git clone https://gitea.bubuit.net/oib/aitbc.git aitbc || {
# Try alternative URL
git clone http://10.0.3.107:3000/oib/aitbc.git aitbc || error "Failed to clone repository"
}
cd /opt/aitbc
success "Repository cloned successfully"
}
# Setup Python virtual environments
setup_venvs() {
log "Setting up Python virtual environments..."
# Wallet service
log "Setting up wallet service..."
cd /opt/aitbc/apps/wallet
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
pip install fastapi uvicorn pydantic httpx python-dotenv websockets
# Coordinator API
log "Setting up coordinator API..."
cd /opt/aitbc/apps/coordinator-api
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
else
pip install fastapi uvicorn pydantic httpx python-dotenv
fi
# Exchange API
log "Setting up exchange API..."
cd /opt/aitbc/apps/exchange
python3 -m venv .venv
source .venv/bin/activate
pip install --upgrade pip
if [ -f "requirements.txt" ]; then
pip install -r requirements.txt
else
pip install fastapi uvicorn pydantic python-multipart
fi
success "Virtual environments setup completed"
}
# Install systemd services
install_services() {
log "Installing systemd services..."
# Install core services
services=(
"aitbc-wallet.service"
"aitbc-coordinator-api.service"
"aitbc-exchange-api.service"
"aitbc-blockchain-rpc.service"
)
for service in "${services[@]}"; do
if [ -f "/opt/aitbc/systemd/$service" ]; then
log "Installing $service..."
cp "/opt/aitbc/systemd/$service" /etc/systemd/system/
else
warning "Service file not found: $service"
fi
done
# Reload systemd
systemctl daemon-reload
success "Systemd services installed"
}
# Create startup script
create_startup_script() {
log "Creating startup script..."
cat > /opt/aitbc/start-services.sh << 'EOF'
#!/bin/bash
# AITBC Services Startup Script
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $1"
}
log "Starting AITBC services..."
# Start wallet service
log "Starting wallet service..."
cd /opt/aitbc/apps/wallet
source .venv/bin/activate
nohup python simple_daemon.py > /var/log/aitbc-wallet.log 2>&1 &
echo $! > /var/run/aitbc-wallet.pid
# Start coordinator API
log "Starting coordinator API..."
cd /opt/aitbc/apps/coordinator-api/src
source ../.venv/bin/activate
nohup python -m uvicorn app.main:app --host 0.0.0.0 --port 8000 > /var/log/aitbc-coordinator.log 2>&1 &
echo $! > /var/run/aitbc-coordinator.pid
# Start exchange API
log "Starting exchange API..."
cd /opt/aitbc/apps/exchange
source .venv/bin/activate
nohup python simple_exchange_api.py > /var/log/aitbc-exchange.log 2>&1 &
echo $! > /var/run/aitbc-exchange.pid
log "All services started"
EOF
chmod +x /opt/aitbc/start-services.sh
success "Startup script created"
}
# Create health check script
create_health_check() {
log "Creating health check script..."
cat > /opt/aitbc/health-check.sh << 'EOF'
#!/bin/bash
# AITBC Health Check Script
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
check_service() {
local name=$1
local url=$2
local expected=${3:-200}
if curl -s -o /dev/null -w "%{http_code}" "$url" | grep -q "$expected"; then
echo -e "${GREEN}✓${NC} $name is healthy"
return 0
else
echo -e "${RED}✗${NC} $name is unhealthy"
return 1
fi
}
echo "AITBC Service Health Check"
echo "========================"
# Check wallet service
check_service "Wallet API" "http://localhost:8003/health"
# Check exchange API
check_service "Exchange API" "http://localhost:8001/api/health"
# Check coordinator API
check_service "Coordinator API" "http://localhost:8000/health"
# Check process status
echo ""
echo "Process Status:"
ps aux | grep -E "simple_daemon|uvicorn|simple_exchange_api" | grep -v grep | while read line; do
echo -e "${GREEN}✓${NC} $line"
done
EOF
chmod +x /opt/aitbc/health-check.sh
success "Health check script created"
}
# Start services
start_services() {
log "Starting AITBC services..."
# Try systemd first
if systemctl start aitbc-wallet aitbc-coordinator-api aitbc-exchange-api 2>/dev/null; then
log "Services started via systemd"
sleep 5
# Check if services are running
if systemctl is-active --quiet aitbc-wallet aitbc-coordinator-api aitbc-exchange-api; then
success "Services started successfully via systemd"
else
warning "Some systemd services failed, falling back to manual startup"
/opt/aitbc/start-services.sh
fi
else
log "Systemd services not available, using manual startup"
/opt/aitbc/start-services.sh
fi
# Wait for services to initialize
sleep 10
# Run health check
/opt/aitbc/health-check.sh
}
# Setup auto-start
setup_autostart() {
log "Setting up auto-start..."
# Create systemd service for startup script
cat > /etc/systemd/system/aitbc-startup.service << EOF
[Unit]
Description=AITBC Services Startup
After=network.target
[Service]
Type=oneshot
ExecStart=/opt/aitbc/start-services.sh
RemainAfterExit=yes
User=root
Group=root
[Install]
WantedBy=multi-user.target
EOF
systemctl enable aitbc-startup.service
success "Auto-start configured"
}
# Main function
main() {
log "Starting AITBC local setup..."
check_root
check_prerequisites
clone_repo
setup_venvs
install_services
create_startup_script
create_health_check
start_services
setup_autostart
success "AITBC setup completed!"
echo ""
echo "Service Information:"
echo " Wallet API: http://localhost:8003/health"
echo " Exchange API: http://localhost:8001/api/health"
echo " Coordinator API: http://localhost:8000/health"
echo ""
echo "Management Commands:"
echo " Health check: /opt/aitbc/health-check.sh"
echo " Restart services: /opt/aitbc/start-services.sh"
echo " View logs: tail -f /var/log/aitbc-*.log"
}
# Run main function
main "$@"

View File

@@ -10,7 +10,7 @@ Group=root
WorkingDirectory=/opt/aitbc/apps/wallet
Environment=PYTHONPATH=/opt/aitbc/apps/wallet/src:/opt/aitbc/packages/py/aitbc-crypto/src:/opt/aitbc/packages/py/aitbc-sdk/src
Environment=COORDINATOR_API_KEY=test-key
ExecStart=/usr/bin/python3 /opt/aitbc/apps/wallet/simple_daemon.py
ExecStart=/opt/aitbc/apps/wallet/.venv/bin/python /opt/aitbc/apps/wallet/simple_daemon.py
KillMode=mixed
TimeoutStopSec=5
PrivateTmp=false