secubox-deb/packages/secubox-streamlit/config/streamlit.toml.example
CyberMind 832141cd0a
feat(secubox-streamlit): v1.2.2 — per-app idle timeout + wake-on-demand (closes #331) (#334)
* docs(plan): #331 streamlit idle-timeout + wake-on-demand (ref #331)

* feat(streamlit): add idle-tracking helpers to streamlitctl (ref #331)

Add the foundation for per-app idle timeout / wake-on-demand:

- IDLE_STATE_DIR constant at /var/lib/secubox/streamlit/idle
- _idle_config: read [idle] settings from /etc/secubox/streamlit.toml
  with safe defaults
- _app_running: check whether an app is listening on its port INSIDE
  the LXC (existing inline ss check is host-side and unreliable)
- _app_active_conns: count ESTABLISHED connections to an app's port
- _app_last_active / _app_touch_active: per-app last-activity epoch
  tracked via state-file mtime

Wire cmd_app_start to touch the state file on every successful start
so a freshly-started app does not get immediately reaped by the
upcoming idle-check.

All helpers degrade gracefully when the LXC is down (lxc_running
guard) and the helpers themselves do not change any existing
behaviour — they are purely additive.

* feat(streamlit): streamlitctl app idle-check — stop idle apps past timeout (ref #331)

Add cmd_app_idle_check that iterates apps under $APPS_PATH and stops
those that have had zero ESTABLISHED connections for longer than the
configured timeout_minutes (default 30, from [idle] in streamlit.toml).
Apps with active connections get their state file touched; apps with no
state file yet are touched too (grace period). Master switch via [idle]
enabled in /etc/secubox/streamlit.toml.

Wire idle-check + wake into the `app` subcommand dispatcher; wake's
function (cmd_app_wake) lands in the next commit (dead branch until
then). Usage line updated to include both new subcommands.

* feat(streamlit): streamlitctl app wake — lazy start + poll for port (ref #331)

Adds cmd_app_wake <name> [wait_seconds] (default 30s):
- returns 0 if already running OR if the app comes up within wait_seconds
- returns 1 on start failure or poll timeout
- returns 2 on misuse (missing name, unknown app)

Uses _app_running for readiness probing and _app_touch_active to refresh
the idle marker on a successful wake. Polls every 1s for portability.

The case-block dispatcher (idle-check / wake) was already wired in Task 2.

* feat(streamlit): systemd idle-sweep timer (every 5 min) (ref #331)

Ship secubox-streamlit-idle.service (oneshot, runs
`streamlitctl app idle-check`) and secubox-streamlit-idle.timer
(OnBootSec=5min, OnUnitActiveSec=5min) so idle Streamlit apps are
auto-suspended without a separate cron.

Wire the units through debian/secubox-streamlit.install (the package
uses a hand-rolled override_dh_auto_install, so dh_installsystemd's
auto-detection by package.suffix name doesn't pick them up — explicit
.install is needed). Enable/disable the timer in postinst/prerm
alongside the main service.

* feat(streamlit): POST /apps/{name}/wake — lazy start API endpoint (ref #331)

* feat(streamlit): default [idle] config block (timeout 30 min) (ref #331)

* chore(streamlit): bump to v1.2.2 with idle-timeout + wake summary (closes #331)

---------

Co-authored-by: CyberMind-FR <gandalf@Gk2.net>
2026-05-22 07:58:33 +02:00

64 lines
1.5 KiB
Plaintext

# SecuBox Streamlit Platform Configuration
# Location: /etc/secubox/streamlit.toml
[main]
enabled = true
http_port = "8501"
http_host = "0.0.0.0"
data_path = "/srv/streamlit"
memory_limit = "4G"
[server]
headless = "true"
browser_gather_usage_stats = "false"
theme_base = "dark"
theme_primary_color = "#0ff"
# Gitea integration (optional)
[gitea]
enabled = false
user = "admin"
url = "http://localhost:3001"
# token = "your_gitea_token"
# App definitions
# [apps.myapp]
# name = "My App"
# path = "myapp.py"
# enabled = true
# repo = "user/repo"
# Instance definitions (running instances with domain routing)
# [instances.myinstance]
# name = "myinstance"
# app = "myapp"
# port = "8501"
# enabled = true
# autostart = true
# emancipated = true
# domain = "myapp.example.com"
# Power management (sleep/wake optimization)
[power]
auto_pause = false
auto_pause_minutes = 30
# presence_events enables banner injection on wake/sleep
presence_events = true
# metoblizer_log enables activity logging to metoblizer
metoblizer_log = false
metoblizer_endpoint = "http://localhost:9300/api/v1/metoblizer/ingest"
[idle]
# Stop streamlit apps that haven't served any ESTABLISHED connection
# for this many minutes. Set to 0 to disable. Default 30.
timeout_minutes = 30
# How often the systemd timer runs the sweep. Informational — the
# actual timer is in secubox-streamlit-idle.timer; keep them in sync
# if you change either.
check_interval_minutes = 5
# Master switch. false = streamlitctl app idle-check exits 0 without
# touching anything.
enabled = true