ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
Keep the panel booting when uptime can't resume
Juan Denis498901e70e5a
diff --git a/backend/app/__init__.py b/backend/app/__init__.pyindex d3009860..ce5dae21 100644--- a/backend/app/__init__.py+++ b/backend/app/__init__.py@@ -488,11 +488,16 @@ def create_app(config_name=None):# Threshold alerting and the uptime sampler are switched on from# the UI; without this they silently stop at the next restart# while their status still reads "enabled".+ # Best effort: a resume failure must never stop the panel booting.if not app.config.get('TESTING'):from app.services.monitoring_service import MonitoringServicefrom app.services.uptime_service import UptimeService- MonitoringService.resume_if_enabled(app)- UptimeService.resume_if_enabled()+ for resume in (lambda: MonitoringService.resume_if_enabled(app),+ UptimeService.resume_if_enabled):+ try:+ resume()+ except Exception: # noqa: BLE001+ app.logger.exception('Could not resume a background monitor at boot')# Resume the embedded agent when this panel is linked to a master# ServerKit panel (ServerKit-to-ServerKit peering).diff --git a/backend/app/services/uptime_service.py b/backend/app/services/uptime_service.pyindex 3512a06b..1541dbf9 100644--- a/backend/app/services/uptime_service.py+++ b/backend/app/services/uptime_service.py@@ -45,8 +45,10 @@ class UptimeService:@classmethoddef _load_history(cls) -> Dict:- """Load uptime history from file, or a fresh one if unreadable."""- cls._ensure_data_dir()+ """Load uptime history from file, or a fresh one if unreadable.++ Reading creates nothing: at boot the data dir may not exist and may not+ be creatable (the container runs unprivileged)."""return load_json_config(cls.UPTIME_FILE, {'start_time': datetime.now().isoformat(),'checks': [],diff --git a/backend/tests/test_alerting_resumes_at_boot.py b/backend/tests/test_alerting_resumes_at_boot.pyindex a27f4cac..1ae8df43 100644--- a/backend/tests/test_alerting_resumes_at_boot.py+++ b/backend/tests/test_alerting_resumes_at_boot.py@@ -87,3 +87,15 @@ def test_stopped_uptime_tracking_stays_stopped(uptime):def test_never_started_uptime_tracking_stays_off(uptime):UptimeService.resume_if_enabled()assert uptime == []+++def test_resume_does_not_create_an_uncreatable_data_dir(uptime, tmp_path, monkeypatch):+ """The image runs unprivileged and cannot create /var/lib/serverkit; boot+ called resume and crashed on that makedirs before serving anything."""+ blocker = tmp_path / 'not-a-dir'+ blocker.write_text('')+ data_dir = blocker / 'serverkit' # makedirs here always fails+ monkeypatch.setattr(UptimeService, 'DATA_DIR', str(data_dir))+ monkeypatch.setattr(UptimeService, 'UPTIME_FILE', str(data_dir / 'uptime_history.json'))+ UptimeService.resume_if_enabled()+ assert uptime == [] and not data_dir.exists()