-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstart
More file actions
executable file
·632 lines (610 loc) · 22.2 KB
/
start
File metadata and controls
executable file
·632 lines (610 loc) · 22.2 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
MIN_PYTHON_VERSION="3.10"
VENV_DIR="$ROOT_DIR/.venv"
VENV_PYTHON="$ROOT_DIR/.venv/bin/python"
RUNTIME_LOCKFILE="$ROOT_DIR/requirements.lock"
RPI_CONSTRAINT_TOKEN="RPI_Constraint"
print_rpi_constraint_help() {
cat <<'EOF'
Usage:
./start RPI_Constraint [constraint options] [-- start.py options]
Constraint options:
--profile NAME One of: pi3b, pi4_2gb, pi5_4gb (default: pi4_2gb)
--container-name VALUE Docker container name override for metrics/debugging
--platform VALUE Docker platform override (for example linux/arm64)
--cpus VALUE Docker CPU quota (for example 2.0)
--cpuset-cpus VALUE CPU pinning set (for example 0-1)
--memory VALUE Docker memory limit (for example 2g)
--memory-swap VALUE Docker swap limit (default: same as memory)
--blkio-weight VALUE Docker blkio weight 10..1000 (default from profile)
--pids-limit VALUE Docker pids limit
--host-port VALUE Host+container dashboard port (default: 8080)
--image VALUE Docker image (default: python:3.11-slim)
--net-delay-ms VALUE Simulated network base delay in ms
--net-jitter-ms VALUE Simulated network jitter in ms
--net-loss-pct VALUE Simulated packet loss percentage
--cpu-contention-workers VALUE Optional synthetic CPU contention workers (default 0)
--cpu-contention-after-s VALUE Delay before CPU contention starts (default 0)
--cpu-contention-duration-s VALUE CPU contention duration in seconds (0 = until exit)
--io-contention-workers VALUE Optional synthetic disk contention workers (default 0)
--io-contention-after-s VALUE Delay before disk contention starts (default 0)
--io-contention-duration-s VALUE Disk contention duration in seconds (0 = until exit)
--thermal-throttle-after-s VALUE Delay before thermal phase starts (default 0 disabled)
--thermal-throttle-workers VALUE Extra CPU contention workers in thermal phase (default 0)
--thermal-throttle-duration-s VALUE Thermal phase duration in seconds (0 = until exit)
--netem Force-enable netem shaping inside container
--no-netem Disable netem shaping inside container
-h, --help Show this help
Examples:
./start RPI_Constraint --profile pi4_2gb
./start RPI_Constraint --profile pi3b --host-port 8090 -- --config config/settings.json
./start RPI_Constraint --profile pi4_2gb --thermal-throttle-after-s 180 --thermal-throttle-workers 1
EOF
}
run_rpi_constraint_mode() {
local profile="${RPI_CONSTRAINT_PROFILE:-pi4_2gb}"
local container_name_override=""
local platform_override=""
local cpus_override=""
local cpuset_override=""
local memory_override=""
local memory_swap_override=""
local blkio_weight_override=""
local pids_limit_override=""
local host_port_override=""
local image_override=""
local net_delay_override=""
local net_jitter_override=""
local net_loss_override=""
local cpu_contention_workers_override=""
local cpu_contention_after_override=""
local cpu_contention_duration_override=""
local io_contention_workers_override=""
local io_contention_after_override=""
local io_contention_duration_override=""
local thermal_after_override=""
local thermal_workers_override=""
local thermal_duration_override=""
local netem_override=""
local -a forwarded_args=()
local -a docker_tty_flags=("-i")
while [ "$#" -gt 0 ]; do
case "$1" in
--profile)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --profile" >&2
exit 1
fi
profile="$2"
shift 2
continue
;;
--container-name)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --container-name" >&2
exit 1
fi
container_name_override="$2"
shift 2
continue
;;
--platform)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --platform" >&2
exit 1
fi
platform_override="$2"
shift 2
continue
;;
--cpus)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --cpus" >&2
exit 1
fi
cpus_override="$2"
shift 2
continue
;;
--cpuset-cpus)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --cpuset-cpus" >&2
exit 1
fi
cpuset_override="$2"
shift 2
continue
;;
--memory)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --memory" >&2
exit 1
fi
memory_override="$2"
shift 2
continue
;;
--memory-swap)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --memory-swap" >&2
exit 1
fi
memory_swap_override="$2"
shift 2
continue
;;
--blkio-weight)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --blkio-weight" >&2
exit 1
fi
blkio_weight_override="$2"
shift 2
continue
;;
--pids-limit)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --pids-limit" >&2
exit 1
fi
pids_limit_override="$2"
shift 2
continue
;;
--host-port)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --host-port" >&2
exit 1
fi
host_port_override="$2"
shift 2
continue
;;
--image)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --image" >&2
exit 1
fi
image_override="$2"
shift 2
continue
;;
--net-delay-ms)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --net-delay-ms" >&2
exit 1
fi
net_delay_override="$2"
shift 2
continue
;;
--net-jitter-ms)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --net-jitter-ms" >&2
exit 1
fi
net_jitter_override="$2"
shift 2
continue
;;
--net-loss-pct)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --net-loss-pct" >&2
exit 1
fi
net_loss_override="$2"
shift 2
continue
;;
--cpu-contention-workers)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --cpu-contention-workers" >&2
exit 1
fi
cpu_contention_workers_override="$2"
shift 2
continue
;;
--cpu-contention-after-s)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --cpu-contention-after-s" >&2
exit 1
fi
cpu_contention_after_override="$2"
shift 2
continue
;;
--cpu-contention-duration-s)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --cpu-contention-duration-s" >&2
exit 1
fi
cpu_contention_duration_override="$2"
shift 2
continue
;;
--io-contention-workers)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --io-contention-workers" >&2
exit 1
fi
io_contention_workers_override="$2"
shift 2
continue
;;
--io-contention-after-s)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --io-contention-after-s" >&2
exit 1
fi
io_contention_after_override="$2"
shift 2
continue
;;
--io-contention-duration-s)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --io-contention-duration-s" >&2
exit 1
fi
io_contention_duration_override="$2"
shift 2
continue
;;
--thermal-throttle-after-s)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --thermal-throttle-after-s" >&2
exit 1
fi
thermal_after_override="$2"
shift 2
continue
;;
--thermal-throttle-workers)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --thermal-throttle-workers" >&2
exit 1
fi
thermal_workers_override="$2"
shift 2
continue
;;
--thermal-throttle-duration-s)
if [ "$#" -lt 2 ]; then
echo "[start] Missing value for --thermal-throttle-duration-s" >&2
exit 1
fi
thermal_duration_override="$2"
shift 2
continue
;;
--netem)
netem_override="1"
shift
continue
;;
--no-netem)
netem_override="0"
shift
continue
;;
-h|--help)
print_rpi_constraint_help
exit 0
;;
--)
shift
while [ "$#" -gt 0 ]; do
forwarded_args+=("$1")
shift
done
break
;;
*)
forwarded_args+=("$1")
shift
continue
;;
esac
done
local profile_platform="linux/arm64"
local profile_cpus="2.0"
local profile_cpuset="0-1"
local profile_memory="2g"
local profile_memory_swap="2g"
local profile_blkio_weight="500"
local profile_pids_limit="256"
local profile_net_delay_ms="6"
local profile_net_jitter_ms="2"
local profile_net_loss_pct="0.20"
local profile_cpu_contention_workers="0"
local profile_cpu_contention_after_s="0"
local profile_cpu_contention_duration_s="0"
local profile_io_contention_workers="0"
local profile_io_contention_after_s="0"
local profile_io_contention_duration_s="0"
local profile_thermal_after_s="0"
local profile_thermal_workers="0"
local profile_thermal_duration_s="0"
case "$profile" in
pi3b)
profile_platform="linux/arm/v7"
profile_cpus="1.2"
profile_cpuset="0-1"
profile_memory="1g"
profile_memory_swap="1g"
profile_blkio_weight="450"
profile_pids_limit="192"
profile_net_delay_ms="12"
profile_net_jitter_ms="4"
profile_net_loss_pct="0.50"
;;
pi4_2gb)
;;
pi5_4gb)
profile_platform="linux/arm64"
profile_cpus="3.0"
profile_cpuset="0-3"
profile_memory="4g"
profile_memory_swap="4g"
profile_blkio_weight="600"
profile_pids_limit="384"
profile_net_delay_ms="3"
profile_net_jitter_ms="1"
profile_net_loss_pct="0.10"
;;
*)
echo "[start] Unknown RPI constraint profile: ${profile}" >&2
echo "[start] Supported profiles: pi3b, pi4_2gb, pi5_4gb" >&2
exit 1
;;
esac
local platform="${platform_override:-${RPI_CONSTRAINT_PLATFORM:-$profile_platform}}"
local cpus="${cpus_override:-${RPI_CONSTRAINT_CPUS:-$profile_cpus}}"
local cpuset_cpus="${cpuset_override:-${RPI_CONSTRAINT_CPUSET_CPUS:-$profile_cpuset}}"
local memory="${memory_override:-${RPI_CONSTRAINT_MEMORY:-$profile_memory}}"
local memory_swap="${memory_swap_override:-${RPI_CONSTRAINT_MEMORY_SWAP:-$profile_memory_swap}}"
local blkio_weight="${blkio_weight_override:-${RPI_CONSTRAINT_BLKIO_WEIGHT:-$profile_blkio_weight}}"
local pids_limit="${pids_limit_override:-${RPI_CONSTRAINT_PIDS_LIMIT:-$profile_pids_limit}}"
local host_port="${host_port_override:-${RPI_CONSTRAINT_HOST_PORT:-8080}}"
local image="${image_override:-${RPI_CONSTRAINT_IMAGE:-python:3.11-slim}}"
local net_delay_ms="${net_delay_override:-${RPI_CONSTRAINT_NET_DELAY_MS:-$profile_net_delay_ms}}"
local net_jitter_ms="${net_jitter_override:-${RPI_CONSTRAINT_NET_JITTER_MS:-$profile_net_jitter_ms}}"
local net_loss_pct="${net_loss_override:-${RPI_CONSTRAINT_NET_LOSS_PCT:-$profile_net_loss_pct}}"
local cpu_contention_workers="${cpu_contention_workers_override:-${RPI_CONSTRAINT_CPU_CONTENTION_WORKERS:-$profile_cpu_contention_workers}}"
local cpu_contention_after_s="${cpu_contention_after_override:-${RPI_CONSTRAINT_CPU_CONTENTION_AFTER_S:-$profile_cpu_contention_after_s}}"
local cpu_contention_duration_s="${cpu_contention_duration_override:-${RPI_CONSTRAINT_CPU_CONTENTION_DURATION_S:-$profile_cpu_contention_duration_s}}"
local io_contention_workers="${io_contention_workers_override:-${RPI_CONSTRAINT_IO_CONTENTION_WORKERS:-$profile_io_contention_workers}}"
local io_contention_after_s="${io_contention_after_override:-${RPI_CONSTRAINT_IO_CONTENTION_AFTER_S:-$profile_io_contention_after_s}}"
local io_contention_duration_s="${io_contention_duration_override:-${RPI_CONSTRAINT_IO_CONTENTION_DURATION_S:-$profile_io_contention_duration_s}}"
local thermal_throttle_after_s="${thermal_after_override:-${RPI_CONSTRAINT_THERMAL_THROTTLE_AFTER_S:-$profile_thermal_after_s}}"
local thermal_throttle_workers="${thermal_workers_override:-${RPI_CONSTRAINT_THERMAL_THROTTLE_WORKERS:-$profile_thermal_workers}}"
local thermal_throttle_duration_s="${thermal_duration_override:-${RPI_CONSTRAINT_THERMAL_THROTTLE_DURATION_S:-$profile_thermal_duration_s}}"
local netem_enabled="${netem_override:-${RPI_CONSTRAINT_NETEM:-1}}"
local run_stamp
run_stamp="$(date +%s)"
local container_name="${container_name_override:-${RPI_CONSTRAINT_CONTAINER_NAME:-rpi_constraint_${profile}_${run_stamp}}}"
if [ -t 0 ] && [ -t 1 ]; then
docker_tty_flags=("-it")
fi
if ! command -v docker >/dev/null 2>&1; then
echo "Docker is required for RPI_Constraint mode. Install Docker Desktop/Engine and retry." >&2
exit 1
fi
local docker_supports_blkio="0"
if docker run --help 2>/dev/null | grep -q -- '--blkio-weight'; then
docker_supports_blkio="1"
fi
echo "[start] RPI_Constraint mode enabled." >&2
echo "[start] Profile=${profile} platform=${platform} cpus=${cpus} cpuset=${cpuset_cpus} memory=${memory} pids=${pids_limit} blkio_weight=${blkio_weight}" >&2
if [ "$netem_enabled" = "1" ]; then
echo "[start] Netem=${net_delay_ms}ms +/- ${net_jitter_ms}ms loss=${net_loss_pct}% (eth0)" >&2
else
echo "[start] Netem disabled." >&2
fi
echo "[start] Synthetic contention cpu_workers=${cpu_contention_workers} io_workers=${io_contention_workers} thermal_workers=${thermal_throttle_workers}" >&2
if [ "${thermal_throttle_after_s}" != "0" ] && [ "${thermal_throttle_workers}" != "0" ]; then
echo "[start] Thermal phase starts after ${thermal_throttle_after_s}s for ${thermal_throttle_duration_s}s." >&2
fi
echo "[start] Container name: ${container_name}" >&2
echo "[start] Dashboard URL: http://127.0.0.1:${host_port}" >&2
local -a docker_cmd=(
run --rm "${docker_tty_flags[@]}"
--name "${container_name}"
--platform "${platform}"
--cpus "${cpus}"
--memory "${memory}"
--memory-swap "${memory_swap}"
--memory-swappiness "0"
--pids-limit "${pids_limit}"
)
if [ -n "${cpuset_cpus}" ]; then
docker_cmd+=(--cpuset-cpus "${cpuset_cpus}")
fi
if [ -n "${blkio_weight}" ] && [ "${blkio_weight}" != "0" ] && [ "${docker_supports_blkio}" = "1" ]; then
docker_cmd+=(--blkio-weight "${blkio_weight}")
elif [ -n "${blkio_weight}" ] && [ "${blkio_weight}" != "0" ] && [ "${docker_supports_blkio}" != "1" ]; then
echo "[start] Warning: Docker runtime does not advertise --blkio-weight support; skipping blkio weighting." >&2
fi
if [ "${netem_enabled}" = "1" ]; then
docker_cmd+=(--cap-add NET_ADMIN)
fi
docker_cmd+=(
-p "${host_port}:${host_port}"
-e "HYDROPONICS_DASHBOARD_BIND_HOST=0.0.0.0"
-e "HYDROPONICS_DASHBOARD_BIND_PORT=${host_port}"
-e "HYDROPONICS_DASHBOARD_PORT=${host_port}"
-e "HYDROPONICS_SIM=1"
-e "RPI_NETEM_ENABLED=${netem_enabled}"
-e "RPI_NET_DELAY_MS=${net_delay_ms}"
-e "RPI_NET_JITTER_MS=${net_jitter_ms}"
-e "RPI_NET_LOSS_PCT=${net_loss_pct}"
-e "RPI_CPU_CONTENTION_WORKERS=${cpu_contention_workers}"
-e "RPI_CPU_CONTENTION_AFTER_S=${cpu_contention_after_s}"
-e "RPI_CPU_CONTENTION_DURATION_S=${cpu_contention_duration_s}"
-e "RPI_IO_CONTENTION_WORKERS=${io_contention_workers}"
-e "RPI_IO_CONTENTION_AFTER_S=${io_contention_after_s}"
-e "RPI_IO_CONTENTION_DURATION_S=${io_contention_duration_s}"
-e "RPI_THERMAL_THROTTLE_AFTER_S=${thermal_throttle_after_s}"
-e "RPI_THERMAL_THROTTLE_WORKERS=${thermal_throttle_workers}"
-e "RPI_THERMAL_THROTTLE_DURATION_S=${thermal_throttle_duration_s}"
-v "${ROOT_DIR}:/app"
-w /app
"${image}"
sh -lc '
set -eu
_spawn_cpu_contention() {
local workers="$1"
local delay_s="$2"
local duration_s="$3"
local label="$4"
local i=0
while [ "$i" -lt "$workers" ]; do
local worker_index
worker_index="$i"
(
sleep "$delay_s"
if [ "$duration_s" -gt 0 ] && command -v timeout >/dev/null 2>&1; then
timeout "${duration_s}s" nice -n 19 sh -c "while :; do :; done" >/dev/null 2>&1 || true
else
nice -n 19 sh -c "while :; do :; done" >/dev/null 2>&1
fi
) &
i=$((i + 1))
echo "[start] Spawned ${label} CPU worker ${worker_index}" >&2
done
}
_spawn_io_contention() {
local workers="$1"
local delay_s="$2"
local duration_s="$3"
local i=0
while [ "$i" -lt "$workers" ]; do
local worker_index
worker_index="$i"
(
sleep "$delay_s"
local workload
workload="while :; do dd if=/dev/zero of=/tmp/.rpi_io_${worker_index} bs=4k count=4096 conv=fsync status=none; rm -f /tmp/.rpi_io_${worker_index}; done"
if [ "$duration_s" -gt 0 ] && command -v timeout >/dev/null 2>&1; then
timeout "${duration_s}s" nice -n 19 sh -c "$workload" >/dev/null 2>&1 || true
else
nice -n 19 sh -c "$workload" >/dev/null 2>&1
fi
) &
i=$((i + 1))
echo "[start] Spawned IO contention worker ${worker_index}" >&2
done
}
_as_int_or_zero() {
local raw="$1"
case "$raw" in
''|*[!0-9]*)
echo 0
;;
*)
echo "$raw"
;;
esac
}
CPU_CONTENTION_WORKERS="$(_as_int_or_zero "${RPI_CPU_CONTENTION_WORKERS:-0}")"
CPU_CONTENTION_AFTER_S="$(_as_int_or_zero "${RPI_CPU_CONTENTION_AFTER_S:-0}")"
CPU_CONTENTION_DURATION_S="$(_as_int_or_zero "${RPI_CPU_CONTENTION_DURATION_S:-0}")"
IO_CONTENTION_WORKERS="$(_as_int_or_zero "${RPI_IO_CONTENTION_WORKERS:-0}")"
IO_CONTENTION_AFTER_S="$(_as_int_or_zero "${RPI_IO_CONTENTION_AFTER_S:-0}")"
IO_CONTENTION_DURATION_S="$(_as_int_or_zero "${RPI_IO_CONTENTION_DURATION_S:-0}")"
THERMAL_AFTER_S="$(_as_int_or_zero "${RPI_THERMAL_THROTTLE_AFTER_S:-0}")"
THERMAL_WORKERS="$(_as_int_or_zero "${RPI_THERMAL_THROTTLE_WORKERS:-0}")"
THERMAL_DURATION_S="$(_as_int_or_zero "${RPI_THERMAL_THROTTLE_DURATION_S:-0}")"
if [ "${RPI_NETEM_ENABLED:-0}" = "1" ]; then
if ! command -v tc >/dev/null 2>&1; then
if command -v apt-get >/dev/null 2>&1; then
apt-get update >/dev/null 2>&1 || true
apt-get install -y --no-install-recommends iproute2 >/dev/null 2>&1 || true
fi
fi
if command -v tc >/dev/null 2>&1; then
tc qdisc replace dev eth0 root netem delay "${RPI_NET_DELAY_MS}ms" "${RPI_NET_JITTER_MS}ms" loss "${RPI_NET_LOSS_PCT}%" >/dev/null 2>&1 || true
else
echo "[start] Warning: tc not available in container; skipping netem shaping." >&2
fi
fi
if [ "$CPU_CONTENTION_WORKERS" -gt 0 ]; then
_spawn_cpu_contention "$CPU_CONTENTION_WORKERS" "$CPU_CONTENTION_AFTER_S" "$CPU_CONTENTION_DURATION_S" "base"
fi
if [ "$IO_CONTENTION_WORKERS" -gt 0 ]; then
_spawn_io_contention "$IO_CONTENTION_WORKERS" "$IO_CONTENTION_AFTER_S" "$IO_CONTENTION_DURATION_S"
fi
if [ "$THERMAL_WORKERS" -gt 0 ] && [ "$THERMAL_AFTER_S" -gt 0 ]; then
_spawn_cpu_contention "$THERMAL_WORKERS" "$THERMAL_AFTER_S" "$THERMAL_DURATION_S" "thermal"
fi
python -m pip install --disable-pip-version-check --require-hashes -r requirements.lock
exec nice -n 10 python start.py --ui web --mode simulator "$@"
'
sh
)
if [ "${#forwarded_args[@]}" -gt 0 ]; then
docker_cmd+=("${forwarded_args[@]}")
fi
exec docker "${docker_cmd[@]}"
}
if [ "${1:-}" = "$RPI_CONSTRAINT_TOKEN" ]; then
shift
run_rpi_constraint_mode "$@"
fi
is_compatible_python() {
local candidate="$1"
if ! command -v "$candidate" >/dev/null 2>&1; then
return 1
fi
"$candidate" -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 1)" >/dev/null 2>&1
}
pick_bootstrap_python() {
local candidate
for candidate in \
python \
python3 \
python3.12 \
python3.11 \
python3.10 \
; do
if is_compatible_python "$candidate"; then
printf '%s\n' "$candidate"
return 0
fi
done
return 1
}
if [ -L "$VENV_DIR" ] && [ ! -e "$VENV_DIR" ]; then
echo "[start] Removing broken virtualenv symlink: $VENV_DIR" >&2
rm "$VENV_DIR"
fi
if [ -x "$VENV_PYTHON" ] && is_compatible_python "$VENV_PYTHON"; then
PYTHON_BIN="$VENV_PYTHON"
else
if ! BOOTSTRAP_PYTHON="$(pick_bootstrap_python)"; then
echo "Python ${MIN_PYTHON_VERSION}+ is required but no compatible interpreter was found." >&2
if command -v python3 >/dev/null 2>&1; then
CURRENT_VERSION="$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')")"
echo "Detected python3=${CURRENT_VERSION}. Install python3.10+ or run make setup." >&2
fi
exit 1
fi
"$BOOTSTRAP_PYTHON" -m venv "$VENV_DIR"
PYTHON_BIN="$VENV_PYTHON"
fi
if [ ! -f "$RUNTIME_LOCKFILE" ]; then
echo "Missing runtime lockfile: $RUNTIME_LOCKFILE" >&2
exit 1
fi
"$PYTHON_BIN" -m pip install --disable-pip-version-check --require-hashes -r "$RUNTIME_LOCKFILE"
if ! is_compatible_python "$PYTHON_BIN"; then
echo "Python ${MIN_PYTHON_VERSION}+ is required but no compatible interpreter was found." >&2
if command -v python3 >/dev/null 2>&1; then
CURRENT_VERSION="$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}')")"
echo "Detected python3=${CURRENT_VERSION}. Install python3.10+ or run make setup." >&2
fi
exit 1
fi
exec "$PYTHON_BIN" "$ROOT_DIR/start.py" "$@"