Get stable, aggregated network data for the Network tab from SQLite database
()
| 5665 | return False |
| 5666 | logger.info("[kiosk] install completed") |
| 5667 | |
| 5668 | mode = _kiosk_mode() |
| 5669 | _kiosk_task_set(phase='starting') |
| 5670 | if mode == 'service': |
| 5671 | # Clear a tripped start limit first. The unit gives up after 5 failures |
| 5672 | # in 2 minutes and then refuses every later start with "start request |
| 5673 | # repeated too quickly" until it is reset - so once a box has failed a |
| 5674 | # few times, enabling it fails for a reason that has nothing to do with |
| 5675 | # whatever is actually wrong, and the real error never gets a chance to |
| 5676 | # reappear. This is the same `systemctl reset-failed` the kiosk doctor |
| 5677 | # tells people to run by hand. |
| 5678 | _run_systemctl(['reset-failed', KIOSK_SERVICE]) |
| 5679 | enable_proc = _run_systemctl(['enable', '--now', KIOSK_SERVICE]) |
| 5680 | if enable_proc.returncode != 0: |
| 5681 | err = enable_proc.stderr.strip() or enable_proc.stdout.strip() or 'unknown error' |
| 5682 | logger.error(f"[kiosk] enable --now failed: {err}") |
| 5683 | _kiosk_task_set(phase='failed', |
| 5684 | error=f'Could not start the kiosk service: {err}{_kiosk_failure_detail()}') |
| 5685 | return False |
| 5686 | # `enable --now` returns as soon as the process is spawned, so a kiosk |
| 5687 | # that dies a second later reported success and left the UI waiting on a |
| 5688 | # service that was already gone. Give it a moment and say so instead. |
| 5689 | time.sleep(5) |
| 5690 | state = _systemctl_state_label('ragnar-kiosk') |
| 5691 | if state not in ('active', 'activating'): |
| 5692 | logger.error(f"[kiosk] service did not stay up (state={state})") |
| 5693 | _kiosk_task_set( |
| 5694 | phase='failed', |
| 5695 | error=f'The kiosk service started and then stopped ({state}).' |
| 5696 | f'{_kiosk_failure_detail()}') |
| 5697 | return False |
| 5698 | logger.info("[kiosk] systemd service enabled and started") |
| 5699 | return True |
| 5700 | |
| 5701 | if mode == 'autostart': |
| 5702 | # Autostart mode: the entry covers next login, but spawn into the live |
| 5703 | # session too so enabling from the web UI shows something now. |
| 5704 | if not _kiosk_running(): |
| 5705 | _spawn_kiosk_in_session() |
| 5706 | return True |
| 5707 | |
| 5708 | # The installer returned success but left neither a unit nor an autostart |
| 5709 | # entry. Saying "installed" here would be a lie the UI then waits on. |
| 5710 | logger.error("[kiosk] installer succeeded but nothing was installed") |
| 5711 | _kiosk_task_set(phase='failed', |
| 5712 | error='The installer reported success but installed neither a service nor an ' |
| 5713 | 'autostart entry. Click Diagnose for the full picture.') |
| 5714 | return False |
| 5715 | |
| 5716 | |
| 5717 | def _dispatch_kiosk_change(prev_enabled: bool, new_enabled: bool, settings_changed: bool) -> None: |
| 5718 | """Background worker: install/start/stop the kiosk to match config. |
| 5719 | Handles both modes (autostart .desktop entry on Pi OS Desktop, systemd |
| 5720 | unit on Pi OS Lite) — the installer picks the right one.""" |
| 5721 | _kiosk_task_set(busy=True, phase='starting', error=None, started=time.time()) |
| 5722 | try: |
| 5723 | if new_enabled and not prev_enabled: |
| 5724 | _kiosk_install_and_start() |
nothing calls this directly
no test coverage detected