File size: 7,782 Bytes
93be2a2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | #!/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)" |