#!/bin/bash export PATH="/home/hermeswebui/.local/node/bin:$PATH" BASE_DIR="/workspace/personal/dashboards/VPN_chanel" cd "$BASE_DIR" # Terminate existing stale watchdog, uvicorn on 8000, or next on 3000 python3 -c " import os, signal for pid in os.listdir('/proc'): if pid.isdigit(): try: with open(f'/proc/{pid}/cmdline', 'rb') as f: cmd = f.read().decode('utf-8', errors='ignore') if ('watchdog.py' in cmd) or ('uvicorn' in cmd and '8000' in cmd) or ('next' in cmd and '3000' in cmd): os.kill(int(pid), signal.SIGKILL) except Exception: pass " 2>/dev/null || true sleep 1 # Start Backend detached with memory optimization: 1 worker, limited concurrency, low keepalive cd "$BASE_DIR/backend" python3 -c " import subprocess, os with open('$BASE_DIR/backend.log', 'a') as out: subprocess.Popen( [ '$BASE_DIR/backend/venv/bin/uvicorn', 'app.main:app', '--host', '0.0.0.0', '--port', '8000', '--workers', '1', '--limit-concurrency', '10', '--timeout-keep-alive', '5' ], stdout=out, stderr=out, start_new_session=True ) " # Start Frontend detached with NODE_OPTIONS memory limit (64MB) cd "$BASE_DIR/frontend" python3 -c " import subprocess, os env = os.environ.copy() env['PATH'] = '/home/hermeswebui/.local/node/bin:' + env.get('PATH', '') env['NODE_OPTIONS'] = '--max-old-space-size=64' with open('$BASE_DIR/frontend.log', 'a') as out: subprocess.Popen( ['$BASE_DIR/frontend/node_modules/.bin/next', 'start', '-p', '3000', '-H', '0.0.0.0'], stdout=out, stderr=out, env=env, start_new_session=True ) " sleep 3 echo "Daemonized services initialized with memory optimization."