v0.7.6: launcher auto-start restart, clean Ctrl+C on DB startup

This commit is contained in:
Reditus committed 2026-09-22 11:16:37 +01:00
1 parent 9c61e198fa
commit f48a09e8d3
4 files changed
+77 -46

No files matched your search

+51 -43
View File
@@ -19,22 +19,26 @@ class DatabaseService:
def init_pool(self):
if self.pool is None:
# Retry up to 10 times with 2s delays (20s total) to handle startup race conditions
for attempt in range(10):
try:
self.pool = psycopg2.pool.ThreadedConnectionPool(
minconn=self.min_conn,
maxconn=self.max_conn,
**self.db_config
)
logger.info("Database connection pool initialized")
return self.pool
except Exception as e:
if attempt < 9:
logger.warning(f"DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
time.sleep(2)
else:
logger.error(f"Failed to initialize database pool after 10 attempts: {e}")
self.pool = None
try:
for attempt in range(10):
try:
self.pool = psycopg2.pool.ThreadedConnectionPool(
minconn=self.min_conn,
maxconn=self.max_conn,
**self.db_config
)
logger.info("Database connection pool initialized")
return self.pool
except Exception as e:
if attempt < 9:
logger.warning(f"DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
time.sleep(2)
else:
logger.error(f"Failed to initialize database pool after 10 attempts: {e}")
self.pool = None
except KeyboardInterrupt:
print("\n Stopped during database startup.")
raise SystemExit(0)
return self.pool
def get_connection(self):
@@ -155,33 +159,37 @@ class DashboardDatabaseService:
def init_pool(self):
if self.pool is not None:
return self.pool
for attempt in range(10):
try:
self.pool = psycopg2.pool.ThreadedConnectionPool(
minconn=self.min_conn,
maxconn=self.max_conn,
**self.db_config
)
logger.info("Dashboard database pool initialized")
return self.pool
except psycopg2.OperationalError as e:
if 'does not exist' in str(e) and attempt == 0:
logger.info("Dashboard database does not exist, creating...")
self._ensure_database()
continue
if attempt < 9:
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
time.sleep(2)
else:
logger.error(f"Failed to initialize dashboard pool after 10 attempts: {e}")
self.pool = None
except Exception as e:
if attempt < 9:
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
time.sleep(2)
else:
logger.error(f"Failed to initialize dashboard pool after 10 attempts: {e}")
self.pool = None
try:
for attempt in range(10):
try:
self.pool = psycopg2.pool.ThreadedConnectionPool(
minconn=self.min_conn,
maxconn=self.max_conn,
**self.db_config
)
logger.info("Dashboard database pool initialized")
return self.pool
except psycopg2.OperationalError as e:
if 'does not exist' in str(e) and attempt == 0:
logger.info("Dashboard database does not exist, creating...")
self._ensure_database()
continue
if attempt < 9:
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
time.sleep(2)
else:
logger.error(f"Failed to initialize dashboard pool after 10 attempts: {e}")
self.pool = None
except Exception as e:
if attempt < 9:
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
time.sleep(2)
else:
logger.error(f"Failed to initialize dashboard pool after 10 attempts: {e}")
self.pool = None
except KeyboardInterrupt:
print("\n Stopped during database startup.")
raise SystemExit(0)
return self.pool
def _ensure_database(self):
+10 -3
View File
@@ -430,13 +430,20 @@ class UpdateService:
return False, str(e)
def _restart_app(self):
"""Restart the dashboard via the launcher script to preserve SSH/DB tunnels."""
"""Restart the dashboard through the launcher in auto-start mode.
The launcher re-establishes SSH tunnels and port-forwards, then goes
straight into the dashboard without stopping at the selection menu.
The old process exits below, so the port is free when the new one
binds.
"""
try:
if os.name == 'nt':
launcher = os.path.join(self.project_root, 'launcher.ps1')
if os.path.exists(launcher):
subprocess.Popen(
['powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', launcher],
['powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass',
'-File', launcher, '-AutoStart'],
creationflags=subprocess.CREATE_NEW_CONSOLE
)
else:
@@ -444,7 +451,7 @@ class UpdateService:
else:
launcher = os.path.join(self.project_root, 'start.sh')
if os.path.exists(launcher):
subprocess.Popen(['bash', launcher], start_new_session=True)
subprocess.Popen(['bash', launcher, '--auto-start'], start_new_session=True)
else:
subprocess.Popen([sys.executable, os.path.join(self.project_root, 'run.py')], start_new_session=True)
os._exit(0)
+9
View File
@@ -2,6 +2,10 @@
# This script handles both setup and starting the dashboard.
# Run this script and choose what you want to do.
# -AutoStart skips the menu and starts the dashboard straight away
# (used after self-updates so the panel comes back up unattended).
param([switch]$AutoStart)
$ErrorActionPreference = "Continue"
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
@@ -2819,6 +2823,11 @@ function Rotate-SSHKey {
Show-Banner
if ($AutoStart) {
Start-Dashboard
exit $LASTEXITCODE
}
while ($true) {
Show-Menu
$choice = Read-Host " Enter your choice"
+7
View File
@@ -1040,6 +1040,13 @@ rotate_ssh_key() {
# ── Main Loop ───────────────────────────────────────────────────────────
# --auto-start skips the menu and starts the dashboard straight away
# (used after self-updates so the panel comes back up unattended).
if [ "$1" = "--auto-start" ] || [ "$1" = "--autostart" ]; then
start_dashboard
exit $?
fi
show_banner
while true; do