[Unit] Description=Retrain the Ping River flood forecast models Documentation=https://git.b4l.co.th/B4L/Northern-Thailand-Ping-River-Monitor/-/blob/master/docs/FLOOD_FORECASTING.md After=network-online.target Wants=network-online.target [Service] Type=oneshot User=water-monitor Group=water-monitor WorkingDirectory=/opt/thailand-water-monitor EnvironmentFile=/opt/thailand-water-monitor/.env # Same interpreter as water-monitor.service -- the uv-managed .venv. # scripts/retrain.sh trains into models/.staging, refuses to promote anything # that is not a rain-enabled (hgb-v3) set covering the expected stations, then # renames the bundles into place. The API reloads them on its next hourly # precompute; no restart, so a failed run leaves the old models serving. ExecStart=/bin/bash /opt/thailand-water-monitor/scripts/retrain.sh # HistGradientBoosting is CPU-bound; cap threads so training cannot starve # the API (docs/FLOOD_FORECASTING.md section 6 measured 4 as the sweet spot). Environment=OMP_NUM_THREADS=4 Environment=PYTHONPATH=/opt/thailand-water-monitor Environment=PYTHONUNBUFFERED=1 Nice=15 IOSchedulingClass=idle # 15 stations at ~50 s each plus data load: 12 min observed on 2026-09-12. TimeoutStartSec=45min # Same sandbox as the API unit. NoNewPrivileges=true PrivateTmp=true ProtectSystem=strict ProtectHome=true ReadWritePaths=/opt/thailand-water-monitor CapabilityBoundingSet= StandardOutput=journal StandardError=journal SyslogIdentifier=water-monitor-retrain