| 11453 | # DISPLAY entrypoint (Ragnar.py), not just restart — on a box |
| 11454 | # running the headless entrypoint a plain restart would come |
| 11455 | # back up headless with the panel dark. _apply_display_mode |
| 11456 | # rewrites the unit and schedules its own detached restart. |
| 11457 | new_epd = shared_data.config.get('epd_type') |
| 11458 | ok, dmsg = _apply_display_mode('display', new_epd, validate=False) |
| 11459 | response['message'] = ( |
| 11460 | f'Display set to {new_epd} — switching to display mode…' |
| 11461 | if ok else f'Could not switch to display mode: {dmsg}') |
| 11462 | # Any other restart-bound keys are covered by the same restart. |
| 11463 | else: |
| 11464 | response['message'] = f'{changed} changed - restarting Ragnar service...' |
| 11465 | def _delayed_restart(): |
| 11466 | time.sleep(2) # Give the response time to reach the client |
| 11467 | logger.info(f"Restarting Ragnar service for config change: {changed}") |
| 11468 | subprocess.Popen(['systemctl', 'restart', 'ragnar.service']) |
| 11469 | threading.Thread(target=_delayed_restart, daemon=True).start() |
| 11470 | else: |
| 11471 | logger.debug("Config saved with no restart-bound change — applying live") |
| 11472 | |
| 11473 | return response, 200 |
| 11474 | |
| 11475 | |
| 11476 | # --------------------------------------------------------------------------- |
| 11477 | # Fleet config export / import |
| 11478 | # --------------------------------------------------------------------------- |
| 11479 | # Cosmetic section-title keys (start with __) are never portable. On top of |
| 11480 | # that we split the config into "portable settings" (feature switches, delays, |
| 11481 | # lists, notification prefs) and two groups that must NOT blindly travel |
| 11482 | # between units: |
| 11483 | # * SECRET/IDENTITY keys — device-local state or secret placeholders. Never |
| 11484 | # exported, never applied on import. |
| 11485 | # * HARDWARE/DISPLAY keys — valid to clone across an identical fleet, but a |
| 11486 | # wrong epd_type restarts the service and a wrong orientation blanks the |
| 11487 | # panel, so they are exported under a separate group and only applied on |
| 11488 | # import when the operator opts in. |
| 11489 | CONFIG_EXPORT_EXCLUDE = { |
| 11490 | 'openai_api_token', # secret placeholder; real token lives in .env |
| 11491 | 'wdg_key', # WDGWars API key — per-operator secret, never share |
| 11492 | 'wigle_api_token', # WiGLE API token — per-operator secret, never share |
| 11493 | 'wigle_api_name', # WiGLE API name — per-operator credential |
| 11494 | 'wardrift_api_key', # Wardrift character API key — per-operator secret |
| 11495 | 'wardrift_session_token', # Wardrift signed-in session — per-operator secret |
| 11496 | 'wardrift_username', # Wardrift account name — per-operator identity |
| 11497 | 'wardrift_mesh_key', # Wardrift node API key — per-node secret |
| 11498 | 'wardrift_mesh_port', # per-device serial port of the Meshtastic node |
| 11499 | 'wardrift_mesh_host', # per-install WiFi address of the Meshtastic node |
| 11500 | 'mac_scan_blacklist', # per-device scan blacklist |
| 11501 | 'rusense_node_positions', # per-install physical node layout |
| 11502 | 'rusense_node_names', # per-install node naming |
| 11503 | 'web_bind_interface', # per-device network binding |
| 11504 | } |
| 11505 | |
| 11506 | # Config keys whose value is bound once at process start and cannot be re-read |
| 11507 | # at runtime — only these earn a service restart, and only when their value |
| 11508 | # actually changes. Everything else in the Settings tab applies live, so saving |
| 11509 | # it must NOT bounce the service. |
| 11510 | # |
| 11511 | # `epd_type` is here because the e-Paper driver object is constructed at import |
| 11512 | # time (SharedData() builds the EPD), so a different panel driver cannot be |