ADAPT-Chase's picture
Add files using upload-large-folder tool
93be2a2 verified
#!/bin/bash
# πŸ’€ Death March Enterprise Deployment Script
# Zero human intervention revenue system
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
DEATH_MARCH_HOME="/data/adaptai/platform/aiml/mlops/death_march"
SECRETS_PATH="/data/adaptai/secrets/.env"
DB_PATH="/tmp/death_march"
VLLM_PORT=8000
REDIS_PORT=18000
# Logging
log() {
echo -e "${GREEN}[$(date +'%Y-%m-%d %H:%M:%S')] $1${NC}"
}
error() {
echo -e "${RED}[$(date +'%Y-%m-%d %H:%M:%S')] ERROR: $1${NC}" >&2
}
warning() {
echo -e "${YELLOW}[$(date +'%Y-%m-%d %H:%M:%S')] WARNING: $1${NC}"
}
# Check system requirements
check_requirements() {
log "Checking system requirements..."
# Check Python 3
if ! command -v python3 &> /dev/null; then
error "Python 3 is required but not installed"
exit 1
fi
# Check pip
if ! command -v pip3 &> /dev/null; then
error "pip3 is required but not installed"
exit 1
fi
# Check GPU
if ! command -v nvidia-smi &> /dev/null; then
warning "nvidia-smi not found - GPU features may be limited"
else
log "GPU detected: $(nvidia-smi --query-gpu=name --format=csv,noheader,nounits | head -1)"
fi
# Check ports
if lsof -i :$VLLM_PORT &> /dev/null; then
warning "Port $VLLM_PORT is already in use"
fi
if lsof -i :$REDIS_PORT &> /dev/null; then
warning "Port $REDIS_PORT is already in use"
fi
}
# Install dependencies
install_dependencies() {
log "Installing Death March dependencies..."
cd "$DEATH_MARCH_HOME"
pip3 install -r requirements.txt
log "Dependencies installed successfully"
}
# Validate secrets
validate_secrets() {
log "Validating API keys and secrets..."
cd "$DEATH_MARCH_HOME"
# Check if secrets file exists
if [[ ! -f "$SECRETS_PATH" ]]; then
error "Secrets file not found: $SECRETS_PATH"
error "Please create the file with your API keys"
exit 1
fi
# Run secrets validation
python3 secrets_manager.py
# Check if minimum requirements are met
if ! python3 -c "from secrets_manager import secrets_manager; exit(0 if secrets_manager.is_ready() else 1)"; then
error "Insufficient API keys for deployment"
exit 1
fi
log "Secrets validation passed"
}
# Validate feature flags
validate_flags() {
log "Validating feature flags..."
cd "$DEATH_MARCH_HOME"
# Run flags validation
python3 death_march/flags.py
log "Feature flags validation passed"
}
# Initialize database
init_database() {
log "Initializing Death March database..."
mkdir -p "$DB_PATH"
# Initialize SQLite database
python3 -c "
import sqlite3
conn = sqlite3.connect('$DB_PATH/revenue.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS revenue (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT DEFAULT CURRENT_TIMESTAMP,
strategy TEXT NOT NULL,
gross REAL NOT NULL,
costs REAL NOT NULL DEFAULT 0.0,
net REAL NOT NULL,
gpu_utilized BOOLEAN DEFAULT FALSE,
cycle_duration INTEGER DEFAULT 120
)
''')
conn.commit()
conn.close()
print('Database initialized successfully')
"
log "Database initialized at $DB_PATH/revenue.db"
}
# Start services
start_services() {
log "Starting Death March services..."
# Start DragonflyDB (Redis compatible)
if ! pgrep -f "dragonfly" > /dev/null; then
log "Starting DragonflyDB..."
dragonfly --bind 0.0.0.0 --port $REDIS_PORT --dbfilename dragonfly.rdb --dir /tmp &
sleep 2
fi
# Check if vLLM is running
if ! curl -f http://localhost:$VLLM_PORT/health > /dev/null 2>&1; then
warning "vLLM server not detected on port $VLLM_PORT"
warning "Please start vLLM manually: python3 elizabeth_vllm_serve.py"
else
log "vLLM server detected and healthy"
fi
}
# Start Death March engine
start_death_march() {
log "Starting Death March engine..."
cd "$DEATH_MARCH_HOME"
# Start with supervisor if available
if command -v supervisorctl &> /dev/null; then
log "Using supervisor for process management"
supervisorctl reread
supervisorctl update
supervisorctl start death_march death_march_monitor
else
log "Starting Death March directly"
nohup python3 deploy.py > /tmp/death_march.log 2>&1 &
echo $! > /tmp/death_march.pid
fi
log "Death March engine started"
}
# Monitor startup
monitor_startup() {
log "Monitoring startup..."
# Wait for initial cycle
sleep 5
# Check if revenue database has entries
python3 -c "
import sqlite3
import time
conn = sqlite3.connect('$DB_PATH/revenue.db')
cursor = conn.cursor()
cursor.execute('SELECT COUNT(*) FROM revenue')
count = cursor.fetchone()[0]
conn.close()
print(f'Revenue cycles completed: {count}')
if count > 0:
print('βœ… Death March is generating revenue')
else:
print('⚠️ Waiting for first revenue cycle...')
"
}
# Main deployment function
deploy() {
log "πŸ’€ Starting Death March deployment..."
check_requirements
install_dependencies
validate_secrets
validate_flags
init_database
start_services
start_death_march
monitor_startup
log "πŸ’€ Death March deployment completed successfully!"
log "Monitor earnings with: make monitor"
log "Interactive CLI: python3 cli.py"
log "Logs: tail -f /tmp/death_march.log"
}
# Emergency stop
stop() {
log "Stopping Death March..."
# Stop via supervisor
if command -v supervisorctl &> /dev/null; then
supervisorctl stop death_march death_march_monitor
fi
# Stop direct processes
if [[ -f /tmp/death_march.pid ]]; then
kill $(cat /tmp/death_march.pid) 2>/dev/null || true
rm /tmp/death_march.pid
fi
# Kill Python processes
pkill -f "deploy.py" 2>/dev/null || true
pkill -f "death_march" 2>/dev/null || true
log "Death March stopped"
}
# Status check
status() {
log "Death March Status Check"
echo "=========================="
# Check processes
if pgrep -f "death_march" > /dev/null; then
echo "βœ… Death March engine: RUNNING"
else
echo "❌ Death March engine: STOPPED"
fi
# Check vLLM
if curl -f http://localhost:$VLLM_PORT/health > /dev/null 2>&1; then
echo "βœ… vLLM server: RUNNING"
else
echo "❌ vLLM server: STOPPED"
fi
# Check Redis/DragonflyDB
if redis-cli -p $REDIS_PORT ping > /dev/null 2>&1; then
echo "βœ… Redis/DragonflyDB: RUNNING"
else
echo "❌ Redis/DragonflyDB: STOPPED"
fi
# Show earnings
python3 -c "
import sqlite3
try:
conn = sqlite3.connect('$DB_PATH/revenue.db')
cursor = conn.cursor()
cursor.execute('SELECT SUM(net), COUNT(*) FROM revenue')
total, cycles = cursor.fetchone()
conn.close()
print(f"πŸ’° Total Earnings: \${total or 0:.2f}")
print(f"πŸ”„ Revenue Cycles: {cycles or 0}")
except:
print('❌ Database not found')
"
}
# Parse command line arguments
case "${1:-deploy}" in
deploy)
deploy
;;
stop)
stop
;;
status)
status
;;
restart)
stop
sleep 2
deploy
;;
*)
echo "Usage: $0 {deploy|stop|status|restart}"
exit 1
;;
esac
# Sign the deployment
log "Deployment script executed by NovaForge"
log "Location: $DEATH_MARCH_HOME"
log "Time: $(date)"