v0.7.6: launcher auto-start restart, clean Ctrl+C on DB startup
This commit is contained in:
1 parent
9c61e198fa
commit
f48a09e8d3
4 files changed
+77
-46
No files matched your search
+51
-43
@@ -19,22 +19,26 @@ class DatabaseService:
|
|||||||
def init_pool(self):
|
def init_pool(self):
|
||||||
if self.pool is None:
|
if self.pool is None:
|
||||||
# Retry up to 10 times with 2s delays (20s total) to handle startup race conditions
|
# Retry up to 10 times with 2s delays (20s total) to handle startup race conditions
|
||||||
for attempt in range(10):
|
try:
|
||||||
try:
|
for attempt in range(10):
|
||||||
self.pool = psycopg2.pool.ThreadedConnectionPool(
|
try:
|
||||||
minconn=self.min_conn,
|
self.pool = psycopg2.pool.ThreadedConnectionPool(
|
||||||
maxconn=self.max_conn,
|
minconn=self.min_conn,
|
||||||
**self.db_config
|
maxconn=self.max_conn,
|
||||||
)
|
**self.db_config
|
||||||
logger.info("Database connection pool initialized")
|
)
|
||||||
return self.pool
|
logger.info("Database connection pool initialized")
|
||||||
except Exception as e:
|
return self.pool
|
||||||
if attempt < 9:
|
except Exception as e:
|
||||||
logger.warning(f"DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
|
if attempt < 9:
|
||||||
time.sleep(2)
|
logger.warning(f"DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
|
||||||
else:
|
time.sleep(2)
|
||||||
logger.error(f"Failed to initialize database pool after 10 attempts: {e}")
|
else:
|
||||||
self.pool = None
|
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
|
return self.pool
|
||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
@@ -155,33 +159,37 @@ class DashboardDatabaseService:
|
|||||||
def init_pool(self):
|
def init_pool(self):
|
||||||
if self.pool is not None:
|
if self.pool is not None:
|
||||||
return self.pool
|
return self.pool
|
||||||
for attempt in range(10):
|
try:
|
||||||
try:
|
for attempt in range(10):
|
||||||
self.pool = psycopg2.pool.ThreadedConnectionPool(
|
try:
|
||||||
minconn=self.min_conn,
|
self.pool = psycopg2.pool.ThreadedConnectionPool(
|
||||||
maxconn=self.max_conn,
|
minconn=self.min_conn,
|
||||||
**self.db_config
|
maxconn=self.max_conn,
|
||||||
)
|
**self.db_config
|
||||||
logger.info("Dashboard database pool initialized")
|
)
|
||||||
return self.pool
|
logger.info("Dashboard database pool initialized")
|
||||||
except psycopg2.OperationalError as e:
|
return self.pool
|
||||||
if 'does not exist' in str(e) and attempt == 0:
|
except psycopg2.OperationalError as e:
|
||||||
logger.info("Dashboard database does not exist, creating...")
|
if 'does not exist' in str(e) and attempt == 0:
|
||||||
self._ensure_database()
|
logger.info("Dashboard database does not exist, creating...")
|
||||||
continue
|
self._ensure_database()
|
||||||
if attempt < 9:
|
continue
|
||||||
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
|
if attempt < 9:
|
||||||
time.sleep(2)
|
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
|
||||||
else:
|
time.sleep(2)
|
||||||
logger.error(f"Failed to initialize dashboard pool after 10 attempts: {e}")
|
else:
|
||||||
self.pool = None
|
logger.error(f"Failed to initialize dashboard pool after 10 attempts: {e}")
|
||||||
except Exception as e:
|
self.pool = None
|
||||||
if attempt < 9:
|
except Exception as e:
|
||||||
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
|
if attempt < 9:
|
||||||
time.sleep(2)
|
logger.warning(f"Dashboard DB pool attempt {attempt + 1}/10 failed, retrying in 2s: {e}")
|
||||||
else:
|
time.sleep(2)
|
||||||
logger.error(f"Failed to initialize dashboard pool after 10 attempts: {e}")
|
else:
|
||||||
self.pool = None
|
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
|
return self.pool
|
||||||
|
|
||||||
def _ensure_database(self):
|
def _ensure_database(self):
|
||||||
|
|||||||
+10
-3
@@ -430,13 +430,20 @@ class UpdateService:
|
|||||||
return False, str(e)
|
return False, str(e)
|
||||||
|
|
||||||
def _restart_app(self):
|
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:
|
try:
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
launcher = os.path.join(self.project_root, 'launcher.ps1')
|
launcher = os.path.join(self.project_root, 'launcher.ps1')
|
||||||
if os.path.exists(launcher):
|
if os.path.exists(launcher):
|
||||||
subprocess.Popen(
|
subprocess.Popen(
|
||||||
['powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', launcher],
|
['powershell', '-NoProfile', '-ExecutionPolicy', 'Bypass',
|
||||||
|
'-File', launcher, '-AutoStart'],
|
||||||
creationflags=subprocess.CREATE_NEW_CONSOLE
|
creationflags=subprocess.CREATE_NEW_CONSOLE
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -444,7 +451,7 @@ class UpdateService:
|
|||||||
else:
|
else:
|
||||||
launcher = os.path.join(self.project_root, 'start.sh')
|
launcher = os.path.join(self.project_root, 'start.sh')
|
||||||
if os.path.exists(launcher):
|
if os.path.exists(launcher):
|
||||||
subprocess.Popen(['bash', launcher], start_new_session=True)
|
subprocess.Popen(['bash', launcher, '--auto-start'], start_new_session=True)
|
||||||
else:
|
else:
|
||||||
subprocess.Popen([sys.executable, os.path.join(self.project_root, 'run.py')], start_new_session=True)
|
subprocess.Popen([sys.executable, os.path.join(self.project_root, 'run.py')], start_new_session=True)
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|||||||
@@ -2,6 +2,10 @@
|
|||||||
# This script handles both setup and starting the dashboard.
|
# This script handles both setup and starting the dashboard.
|
||||||
# Run this script and choose what you want to do.
|
# 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"
|
$ErrorActionPreference = "Continue"
|
||||||
|
|
||||||
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
$ProjectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
||||||
@@ -2819,6 +2823,11 @@ function Rotate-SSHKey {
|
|||||||
|
|
||||||
Show-Banner
|
Show-Banner
|
||||||
|
|
||||||
|
if ($AutoStart) {
|
||||||
|
Start-Dashboard
|
||||||
|
exit $LASTEXITCODE
|
||||||
|
}
|
||||||
|
|
||||||
while ($true) {
|
while ($true) {
|
||||||
Show-Menu
|
Show-Menu
|
||||||
$choice = Read-Host " Enter your choice"
|
$choice = Read-Host " Enter your choice"
|
||||||
|
|||||||
@@ -1040,6 +1040,13 @@ rotate_ssh_key() {
|
|||||||
|
|
||||||
# ── Main Loop ───────────────────────────────────────────────────────────
|
# ── 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
|
show_banner
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
|
|||||||
Reference in new issue
Block a user