From ed743a81b907598dbce4a42337da188e33e2b6bf Mon Sep 17 00:00:00 2001 From: imSp4rky Date: Sat, 28 Nov 2026 16:03:34 -0700 Subject: [PATCH] fix(serve): reject a config reload whose validation exits instead of stopping the server --- docs/reference/configuration/services.md | 14 ++++++++------ tests/remote/unit/test_serve_reload.py | 15 +++++++++++++++ unshackle/commands/serve.py | 4 ++-- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/docs/reference/configuration/services.md b/docs/reference/configuration/services.md index a0e8c56c..79b28c57 100644 --- a/docs/reference/configuration/services.md +++ b/docs/reference/configuration/services.md @@ -188,12 +188,14 @@ list. the whole file again, globs the device directories again, and swaps in the new `users`, `tiers`, `services` and device lists in one step. Open CDM sessions and remote sessions continue; an API key you removed gets `401` on its next request. A file that does not parse - or validate keeps the running settings and logs the reason. A change to `remote_only`, - `services_refresh_interval`, the first PlayReady device, a `dashboard.key` on a server that - started without one, or any command-line flag needs a restart, and the log says so. A reload - that removes `dashboard.key` closes the dashboard: its routes answer `404` and an open - `/api/dashboard/events` connection ends. A new `global_speed_limit` applies to jobs that start after the - reload; running jobs keep their share. Windows has no `SIGHUP`: restart the server there. + or validate keeps the running settings and logs the reason. Each download job starts in a + new process that reads the file on disk, so a job fails until you correct a rejected file. + + A change to `remote_only`, `services_refresh_interval`, the first PlayReady device, a + `dashboard.key` on a server that started without one, or any command-line flag needs a + restart, and the log says so. A reload that removes `dashboard.key` closes the dashboard: its + routes answer `404` and an open `/api/dashboard/events` connection ends. A new + `global_speed_limit` applies to jobs that start after the reload; running jobs keep their share. Windows has no `SIGHUP`: restart the server there. `server_cdm` decides whether the server runs the CDM licensing for that API key. Set it to `true` to enable every service, or to a list of service tags to enable only those. It is `false` diff --git a/tests/remote/unit/test_serve_reload.py b/tests/remote/unit/test_serve_reload.py index 406446a6..38261a64 100644 --- a/tests/remote/unit/test_serve_reload.py +++ b/tests/remote/unit/test_serve_reload.py @@ -73,6 +73,21 @@ def test_invalid_file_keeps_the_running_config(running: tuple[web.Application, P assert config.serve["users"] == {"old": {"devices": ["dev"]}} +def test_config_check_that_exits_is_rejected_not_fatal( + running: tuple[web.Application, Path], caplog: pytest.LogCaptureFixture +) -> None: + app, path = running + path.write_text(yaml.safe_dump({"filename_replacements": {"&": None}}), encoding="utf8") + + with caplog.at_level(logging.ERROR, logger=LOG.name): + assert _reload(app) is False + assert [r.getMessage() for r in caplog.records] == [ + "Config reload rejected, keeping the running config: filename_replacements must map text to text, not {'&': None}" + ] + assert set(app["config"]["users"]) == {"old", "api"} + assert config.serve["users"] == {"old": {"devices": ["dev"]}} + + def test_restart_only_change_is_reported_not_applied( running: tuple[web.Application, Path], caplog: pytest.LogCaptureFixture ) -> None: diff --git a/unshackle/commands/serve.py b/unshackle/commands/serve.py index 84e2bf4a..151f098b 100644 --- a/unshackle/commands/serve.py +++ b/unshackle/commands/serve.py @@ -256,8 +256,8 @@ def reload_config(app: web.Application, *, no_key: bool, serve_widevine: bool, s fresh = Config.from_yaml(config_module.config_path) serve = fresh.serve api_secret = _prepare_serve(serve, no_key, fresh) - except Exception as e: - log.error(f"Config reload rejected, keeping the running config: {e}") + except (Exception, SystemExit) as e: + log.error(f"Config reload rejected, keeping the running config: {str(e).removeprefix('ERROR: ')}") return False changed = [k for k in RESTART_KEYS if serve.get(k) != config.serve.get(k)]