-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
35 lines (31 loc) · 1.16 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
35 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/sh
# Start the Python strategy runtime, then hand PID 1's job to the agent.
#
# The agent cannot do anything useful without the runtime — it validates,
# backtests and ticks every strategy through it — so if the runtime dies the
# container must die too rather than serve a factory that silently stops
# evaluating. That is what the watchdog below enforces.
set -eu
python3 -m nectar_runtime.server &
RUNTIME_PID=$!
# Wait for it to bind before the agent starts probing.
i=0
while [ "$i" -lt 50 ]; do
if node -e "fetch('http://127.0.0.1:'+(process.env.RUNTIME_PORT||8799)+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))" 2>/dev/null; then
break
fi
i=$((i + 1))
sleep 0.2
done
# If the runtime exits at any point, take the whole container down. This polls
# rather than `wait`s: the watchdog runs in a subshell, which is not the
# runtime's parent, so `wait` there would return immediately and kill a
# perfectly healthy container.
(
while kill -0 "$RUNTIME_PID" 2>/dev/null; do
sleep 2
done
echo "strategy runtime exited — stopping the worker" >&2
kill -TERM 1 2>/dev/null || true
) &
exec node apps/agent/dist/index.js