Deploying with pull.sh: the busy guard
./pull.sh no longer restarts the service under running work. Before it changes anything it asks the server what is running; if anything is, it says so and stops.
./pull.sh # deploys only when nothing is running
./pull.sh --check # only report (exit 0 = idle, 3 = busy)
./pull.sh --force # deploy and restart anyway (ends the running work)
What happens
- Step 0, before anything else: the script runs
backend/scripts/deploy_activity.py. If it finds work it prints it and exits with code 3. Nothing is pulled, built, migrated or restarted, so there is no half-deployed state. Run./pull.shagain when the work has finished. - Step 6, right before
systemctl restart: a second check, because work may have started while the build ran. If busy, the restart is skipped, a marker file~/.tradeentry_restart_pendingis written and the summary showsBackend wait(exit code 3). The new code is pulled and built but not live. The next./pull.shthat finds the server idle does the restart, even when there are no new commits. - The restart also stays skipped when the check itself cannot run, unless
--forceis given.
The self-update re-run (--since) skips step 0 because the first run passed it. The first time this feature is deployed, the old pull.sh does the pull and the new one takes over, so only the step 6 check protects that one deploy.
What counts as work
| Source | Detects |
|---|---|
Requests in flight and their background tasks (GET /api/system/activity, middleware in app/core/activity.py) | Every download, sync, pipeline run, backtest and sweep started from the UI (bhav, BSE, MCX, EODIEOD upload, corporate actions, TBS), and any request longer than 10 s |
Auto-sync run locks and RUNNING stats files | The NSE / BSE / MCX scheduled syncs and manual downloads, with each module's own freshness limit |
| Process table | python worker processes below the web server (backtest and sweep pools), and python -m nseeod / nseieod / bseeod / bseieod / mcxeod / mcxieod / carry / tbs, alembic or pytest started by hand in a terminal |
Not counted: the OI live collector (continuous in market hours; a restart skips at most one 3-minute snapshot, shown as information) and the service's own wrappers (uv, app.py, uvicorn, vite preview).
The endpoint
GET /api/system/activity is for the deploy script only. It needs the header X-Deploy-Token, whose value is in backend/tmp/activity.token (created on first use, readable only by the service user, kept across restarts). Without it the answer is 403. An older backend without the endpoint is handled: the script then looks at the process table only and says so.
Limits
- A restart under
--forceends running work; the downloads and syncs have their own rollback rules, but a backtest or sweep is simply lost. - The process look uses
ps, so it works on the VPS (Linux) only; on a PC only the endpoint is asked. - With
uvicorn --reload(development) the reload child looks like a worker; the VPS does not use it.