| | #!/bin/bash |
| | |
| | |
| |
|
| | set -euo pipefail |
| |
|
| | |
| | RED='\033[0;31m' |
| | GREEN='\033[0;32m' |
| | YELLOW='\033[1;33m' |
| | BLUE='\033[0;34m' |
| | NC='\033[0m' |
| |
|
| | |
| | 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 |
| |
|
| | |
| | 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_requirements() { |
| | log "Checking system requirements..." |
| | |
| | |
| | if ! command -v python3 &> /dev/null; then |
| | error "Python 3 is required but not installed" |
| | exit 1 |
| | fi |
| | |
| | |
| | if ! command -v pip3 &> /dev/null; then |
| | error "pip3 is required but not installed" |
| | exit 1 |
| | fi |
| | |
| | |
| | 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 |
| | |
| | |
| | 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() { |
| | log "Installing Death March dependencies..." |
| | |
| | cd "$DEATH_MARCH_HOME" |
| | pip3 install -r requirements.txt |
| | |
| | log "Dependencies installed successfully" |
| | } |
| |
|
| | |
| | validate_secrets() { |
| | log "Validating API keys and secrets..." |
| | |
| | cd "$DEATH_MARCH_HOME" |
| | |
| | |
| | if [[ ! -f "$SECRETS_PATH" ]]; then |
| | error "Secrets file not found: $SECRETS_PATH" |
| | error "Please create the file with your API keys" |
| | exit 1 |
| | fi |
| | |
| | |
| | python3 secrets_manager.py |
| | |
| | |
| | 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_flags() { |
| | log "Validating feature flags..." |
| | |
| | cd "$DEATH_MARCH_HOME" |
| | |
| | |
| | python3 death_march/flags.py |
| | |
| | log "Feature flags validation passed" |
| | } |
| |
|
| | |
| | init_database() { |
| | log "Initializing Death March database..." |
| | |
| | mkdir -p "$DB_PATH" |
| | |
| | |
| | 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() { |
| | log "Starting Death March services..." |
| | |
| | |
| | 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 |
| | |
| | |
| | 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() { |
| | log "Starting Death March engine..." |
| | |
| | cd "$DEATH_MARCH_HOME" |
| | |
| | |
| | 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() { |
| | log "Monitoring startup..." |
| | |
| | |
| | sleep 5 |
| | |
| | |
| | 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...') |
| | " |
| | } |
| |
|
| | |
| | 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" |
| | } |
| |
|
| | |
| | stop() { |
| | log "Stopping Death March..." |
| | |
| | |
| | if command -v supervisorctl &> /dev/null; then |
| | supervisorctl stop death_march death_march_monitor |
| | fi |
| | |
| | |
| | if [[ -f /tmp/death_march.pid ]]; then |
| | kill $(cat /tmp/death_march.pid) 2>/dev/null || true |
| | rm /tmp/death_march.pid |
| | fi |
| | |
| | |
| | pkill -f "deploy.py" 2>/dev/null || true |
| | pkill -f "death_march" 2>/dev/null || true |
| | |
| | log "Death March stopped" |
| | } |
| |
|
| | |
| | status() { |
| | log "Death March Status Check" |
| | echo "==========================" |
| | |
| | |
| | if pgrep -f "death_march" > /dev/null; then |
| | echo "β
Death March engine: RUNNING" |
| | else |
| | echo "β Death March engine: STOPPED" |
| | fi |
| | |
| | |
| | if curl -f http://localhost:$VLLM_PORT/health > /dev/null 2>&1; then |
| | echo "β
vLLM server: RUNNING" |
| | else |
| | echo "β vLLM server: STOPPED" |
| | fi |
| | |
| | |
| | if redis-cli -p $REDIS_PORT ping > /dev/null 2>&1; then |
| | echo "β
Redis/DragonflyDB: RUNNING" |
| | else |
| | echo "β Redis/DragonflyDB: STOPPED" |
| | fi |
| | |
| | |
| | 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') |
| | " |
| | } |
| |
|
| | |
| | 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 |
| |
|
| | |
| | log "Deployment script executed by NovaForge" |
| | log "Location: $DEATH_MARCH_HOME" |
| | log "Time: $(date)" |