From f48a09e8d3edfd36befe302c6846b4bf443f852e Mon Sep 17 00:00:00 2001 From: Reditus <33814724+ReditusDraco@users.noreply.github.com> Date: Tue, 22 Sep 2026 11:16:37 +0100 Subject: [PATCH] v0.7.6: launcher auto-start restart, clean Ctrl+C on DB startup --- app/services/database.py | 94 ++++++++++++++++++++++------------------ app/services/updater.py | 13 ++++-- launcher.ps1 | 9 ++++ start.sh | 7 +++ 4 files changed, 77 insertions(+), 46 deletions(-) diff --git a/app/services/database.py b/app/services/database.py index f9cd82f..eabb721 100644 --- a/app/services/database.py +++ b/app/services/database.py @@ -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): diff --git a/app/services/updater.py b/app/services/updater.py index 0ea31d3..2b9052c 100644 --- a/app/services/updater.py +++ b/app/services/updater.py @@ -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) diff --git a/launcher.ps1 b/launcher.ps1 index 2730c5c..1fb4fa1 100644 --- a/launcher.ps1 +++ b/launcher.ps1 @@ -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" diff --git a/start.sh b/start.sh index 9f0e6ce..bf01d56 100644 --- a/start.sh +++ b/start.sh @@ -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