forked from vllm-project/semantic-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·1046 lines (924 loc) · 25.1 KB
/
install.sh
File metadata and controls
executable file
·1046 lines (924 loc) · 25.1 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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
set -euo pipefail
MODE="${VLLM_SR_INSTALL_MODE:-serve}"
REQUESTED_RUNTIME="${VLLM_SR_RUNTIME:-auto}"
INSTALL_ROOT="${VLLM_SR_INSTALL_ROOT:-$HOME/.local/share/vllm-sr}"
BIN_DIR="${VLLM_SR_BIN_DIR:-$HOME/.local/bin}"
PIP_SPEC="${VLLM_SR_PIP_SPEC:-vllm-sr}"
PYTHON_BIN="${VLLM_SR_PYTHON:-}"
REQUESTED_PLATFORM="${VLLM_SR_INSTALL_PLATFORM:-${VLLM_SR_PLATFORM:-auto}}"
AUTO_LAUNCH="${VLLM_SR_INSTALL_AUTO_LAUNCH:-1}"
OS_NAME=""
SELECTED_RUNTIME=""
LAUNCH_PLATFORM=""
AUTO_LAUNCH_RAN="0"
STYLE_BOLD=""
COLOR_RESET=""
COLOR_ORANGE=""
COLOR_BLUE=""
COLOR_WHITE=""
COLOR_MUTED=""
COLOR_SUCCESS=""
DASHBOARD_URL="http://localhost:8700"
init_colors() {
if [ ! -t 1 ] || [ -n "${NO_COLOR:-}" ]; then
return
fi
STYLE_BOLD=$'\033[1m'
COLOR_RESET=$'\033[0m'
COLOR_ORANGE=$'\033[38;2;254;181;22m'
COLOR_BLUE=$'\033[38;2;48;162;255m'
COLOR_WHITE=$'\033[97m'
COLOR_MUTED=$'\033[38;2;145;158;171m'
COLOR_SUCCESS=$'\033[38;2;111;224;161m'
}
print_logo() {
if [ "${VLLM_SR_NO_LOGO:-0}" = "1" ]; then
return
fi
init_colors
printf '\n'
printf '%b\n' " ${STYLE_BOLD}${COLOR_WHITE} █ █ █▄ ▄█${COLOR_RESET}"
printf '%b\n' " ${STYLE_BOLD}${COLOR_WHITE} ▄▄ ▄█ █ █ █ ▀▄▀ █${COLOR_RESET}"
printf '%b\n' " ${STYLE_BOLD}${COLOR_WHITE} █▄█▀ █ █ █ █${COLOR_RESET}"
printf '%b\n' " ${STYLE_BOLD}${COLOR_WHITE} ▀▀ ▀▀▀▀▀ ▀▀▀▀▀ ▀ ▀${COLOR_RESET}"
printf '%b\n' " ${STYLE_BOLD}${COLOR_WHITE} Semantic Router${COLOR_RESET}"
printf '%b\n' " ${COLOR_MUTED} local installer${COLOR_RESET}"
printf '\n'
}
step() {
printf '%b\n' "${COLOR_BLUE}[step]${COLOR_RESET} $*"
}
done_step() {
printf '%b\n' "${COLOR_SUCCESS}[done]${COLOR_RESET} $*"
}
info() {
printf '%b\n' "${COLOR_MUTED}[info]${COLOR_RESET} $*"
}
warn() {
printf '%b\n' "${COLOR_ORANGE}[warn]${COLOR_RESET} $*" >&2
}
die() {
printf '%b\n' "${COLOR_ORANGE}[error]${COLOR_RESET} $*" >&2
exit 1
}
is_truthy() {
case "${1:-}" in
1|true|TRUE|yes|YES|on|ON)
return 0
;;
*)
return 1
;;
esac
}
is_falsey() {
case "${1:-}" in
0|false|FALSE|no|NO|off|OFF)
return 0
;;
*)
return 1
;;
esac
}
auto_launch_enabled() {
is_truthy "$AUTO_LAUNCH"
}
should_auto_launch() {
auto_launch_enabled || return 1
[ "$MODE" = "serve" ] || return 1
[ "$REQUESTED_RUNTIME" != "skip" ] || return 1
}
print_install_plan() {
local requested_runtime python_cmd python_version runtime_cmd package_manager
requested_runtime="$REQUESTED_RUNTIME"
if [ "$REQUESTED_RUNTIME" = "auto" ]; then
case "$OS_NAME" in
darwin)
requested_runtime="auto -> docker/colima"
;;
linux)
requested_runtime="auto -> podman"
;;
esac
fi
python_cmd="$(detect_python_candidate || true)"
runtime_cmd="$(detect_existing_runtime || true)"
package_manager="$(detect_package_manager_label)"
printf '%b\n' "${COLOR_WHITE}Detected environment${COLOR_RESET}"
printf ' platform %s (%s)\n' "$(detect_os_label)" "$(uname -m)"
printf ' package mgr %s\n' "$package_manager"
if [ -n "$python_cmd" ]; then
python_version="$(python_version_of "$python_cmd")"
printf ' python %s (%s)\n' "$python_cmd" "$python_version"
else
printf ' python not found (needs Python 3.10+)\n'
fi
if [ -n "$runtime_cmd" ]; then
printf ' runtime %s (ready)\n' "$runtime_cmd"
else
printf ' runtime none detected\n'
fi
printf '\n'
printf '%b\n' "${COLOR_WHITE}Install plan${COLOR_RESET}"
printf ' mode %s\n' "$MODE"
printf ' runtime %s\n' "$requested_runtime"
printf ' launch %s\n' "$(if should_auto_launch; then printf 'auto first-run'; else printf 'manual'; fi)"
printf ' platform %s\n' "$(display_platform_plan)"
printf ' python deps pip, setuptools, wheel\n'
printf ' package %s\n' "$PIP_SPEC"
printf ' system deps %s\n' "$(describe_python_dependency_plan "$python_cmd")"
printf ' runtime deps %s\n' "$(describe_runtime_dependency_plan "$runtime_cmd")"
printf ' install root %s\n' "$INSTALL_ROOT"
printf ' launcher %s/vllm-sr\n' "$BIN_DIR"
printf '\n'
}
usage() {
cat <<'EOF'
Usage: install.sh [--mode cli|serve] [--runtime auto|docker|podman|skip]
[--install-root PATH] [--bin-dir PATH] [--pip-spec SPEC]
[--python PATH] [--platform PLATFORM] [--no-launch]
Installs the vLLM Semantic Router CLI into an isolated virtual environment and
links a launcher into ~/.local/bin by default.
Options:
--mode cli|serve Install the CLI only, or prepare a local runtime for
`vllm-sr serve` as well. Default: serve
--runtime auto|docker|podman|skip
Runtime strategy for serve mode. Default: auto
macOS auto -> docker via colima
Linux auto -> podman
--install-root PATH Installation root. Default:
~/.local/share/vllm-sr
--bin-dir PATH Launcher directory. Default: ~/.local/bin
--pip-spec SPEC Python package spec to install. Default: vllm-sr
--python PATH Explicit Python interpreter to use
--platform PLATFORM Platform hint for first-run serve. Use 'amd' for ROCm.
Default: auto
--no-launch Skip the installer's automatic first `vllm-sr serve`
and dashboard open step
-h, --help Show this help message
Environment overrides:
VLLM_SR_INSTALL_MODE
VLLM_SR_RUNTIME
VLLM_SR_INSTALL_ROOT
VLLM_SR_BIN_DIR
VLLM_SR_PIP_SPEC
VLLM_SR_PYTHON
VLLM_SR_INSTALL_PLATFORM
VLLM_SR_INSTALL_AUTO_LAUNCH
EOF
}
has_cmd() {
command -v "$1" >/dev/null 2>&1
}
make_temp_log() {
mktemp "${TMPDIR:-/tmp}/vllm-sr-install.XXXXXX"
}
run_quiet_step() {
local label log_file
label="$1"
shift
step "$label"
log_file="$(make_temp_log)"
if "$@" >"$log_file" 2>&1; then
rm -f "$log_file"
done_step "$label"
return
fi
warn "$label failed. Command output follows:"
cat "$log_file" >&2
rm -f "$log_file"
exit 1
}
run_as_root() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
return
fi
if has_cmd sudo; then
sudo "$@"
return
fi
die "This step requires root or sudo: $*"
}
detect_os() {
case "$(uname -s)" in
Darwin)
OS_NAME="darwin"
;;
Linux)
OS_NAME="linux"
;;
*)
die "Unsupported operating system. This installer supports macOS and Linux."
;;
esac
}
detect_os_label() {
case "$OS_NAME" in
darwin)
printf 'macOS\n'
;;
linux)
printf 'Linux\n'
;;
*)
printf '%s\n' "$OS_NAME"
;;
esac
}
resolve_launch_platform() {
if [ "$REQUESTED_PLATFORM" != "auto" ]; then
printf '%s\n' "$REQUESTED_PLATFORM"
return
fi
if [ -n "${VLLM_SR_PLATFORM:-}" ]; then
printf '%s\n' "$VLLM_SR_PLATFORM"
return
fi
if has_cmd rocm-smi || has_cmd rocminfo || [ -e /dev/kfd ] || [ -d /opt/rocm ]; then
printf 'amd\n'
return
fi
printf '\n'
}
display_platform_plan() {
local platform
platform="$(resolve_launch_platform)"
if [ -n "$platform" ]; then
if [ "$REQUESTED_PLATFORM" = "auto" ]; then
printf '%s (auto-detected)\n' "$platform"
else
printf '%s\n' "$platform"
fi
return
fi
printf 'default\n'
}
detect_primary_ip() {
local python_cmd
python_cmd="$(detect_python_candidate || true)"
if [ -z "$python_cmd" ]; then
return 1
fi
"$python_cmd" -c '
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
s.connect(("8.8.8.8", 80))
print(s.getsockname()[0])
finally:
s.close()
' 2>/dev/null
}
detect_host_label() {
hostname -f 2>/dev/null || hostname 2>/dev/null || printf 'your-server\n'
}
is_remote_session() {
[ -n "${SSH_CONNECTION:-}" ] || [ -n "${SSH_TTY:-}" ]
}
open_dashboard_url() {
case "$OS_NAME" in
darwin)
open "$DASHBOARD_URL" >/dev/null 2>&1
;;
linux)
if has_cmd xdg-open; then
xdg-open "$DASHBOARD_URL" >/dev/null 2>&1
return
fi
if has_cmd gio; then
gio open "$DASHBOARD_URL" >/dev/null 2>&1
return
fi
return 1
;;
*)
return 1
;;
esac
}
print_dashboard_access() {
local primary_ip host_label
primary_ip="$(detect_primary_ip || true)"
host_label="$(detect_host_label)"
printf '%b\n' "${COLOR_WHITE}Dashboard access${COLOR_RESET}"
printf ' local %s\n' "$DASHBOARD_URL"
if [ -n "$primary_ip" ]; then
printf ' network http://%s:8700\n' "$primary_ip"
fi
printf '\n'
if is_remote_session; then
printf '%b\n' "${COLOR_WHITE}Remote access${COLOR_RESET}"
printf ' ssh tunnel ssh -L 8700:localhost:8700 %s@%s\n' "${USER:-user}" "$host_label"
printf ' then open %s\n' "$DASHBOARD_URL"
printf '\n'
fi
}
resolve_launch_dir() {
local current_dir fallback_dir
current_dir="$(pwd)"
if [ -w "$current_dir" ]; then
printf '%s\n' "$current_dir"
return
fi
fallback_dir="${HOME:-$INSTALL_ROOT}"
warn "Current directory is not writable. Falling back to $fallback_dir for the first run."
printf '%s\n' "$fallback_dir"
}
print_restart_command() {
if [ -z "$LAUNCH_PLATFORM" ]; then
LAUNCH_PLATFORM="$(resolve_launch_platform)"
fi
if [ -n "$LAUNCH_PLATFORM" ]; then
printf ' vllm-sr serve --platform %s\n' "$LAUNCH_PLATFORM"
else
printf ' vllm-sr serve\n'
fi
printf ' vllm-sr dashboard\n'
}
python_supports_vllm_sr() {
"$1" -c 'import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 1)' \
>/dev/null 2>&1
}
python_version_of() {
"$1" -c 'import sys; print(".".join(map(str, sys.version_info[:3])))' 2>/dev/null || printf 'unknown\n'
}
find_python() {
if [ -n "$PYTHON_BIN" ]; then
if ! has_cmd "$PYTHON_BIN"; then
die "Requested Python interpreter not found: $PYTHON_BIN"
fi
if ! python_supports_vllm_sr "$PYTHON_BIN"; then
die "Requested Python interpreter must be Python 3.10 or newer: $PYTHON_BIN"
fi
printf '%s\n' "$PYTHON_BIN"
return
fi
for candidate in python3 python3.12 python3.11 python3.10 python; do
if has_cmd "$candidate" && python_supports_vllm_sr "$candidate"; then
printf '%s\n' "$candidate"
return
fi
done
return 1
}
detect_python_candidate() {
find_python
}
detect_linux_pkg_manager() {
for candidate in apt-get dnf yum; do
if has_cmd "$candidate"; then
printf '%s\n' "$candidate"
return
fi
done
return 1
}
detect_package_manager_label() {
local pkg_manager
case "$OS_NAME" in
darwin)
if has_cmd brew; then
printf 'homebrew\n'
else
printf 'homebrew (not found)\n'
fi
;;
linux)
pkg_manager="$(detect_linux_pkg_manager || true)"
if [ -n "$pkg_manager" ]; then
printf '%s\n' "$pkg_manager"
else
printf 'not detected\n'
fi
;;
esac
}
detect_existing_runtime() {
if docker_ready; then
printf 'docker\n'
return
fi
if podman_ready; then
printf 'podman\n'
return
fi
return 1
}
describe_python_dependency_plan() {
local python_cmd pkg_manager
python_cmd="$1"
if [ -n "$python_cmd" ]; then
printf 'none (using %s)\n' "$python_cmd"
return
fi
case "$OS_NAME" in
darwin)
printf 'python via Homebrew\n'
;;
linux)
pkg_manager="$(detect_linux_pkg_manager || true)"
case "$pkg_manager" in
apt-get)
printf 'python3, python3-venv, python3-pip via apt-get\n'
;;
dnf)
printf 'python3, python3-pip via dnf\n'
;;
yum)
printf 'python3, python3-pip via yum\n'
;;
*)
printf 'python 3.10+ required (install manually)\n'
;;
esac
;;
esac
}
describe_runtime_dependency_plan() {
local runtime_cmd preferred_runtime pkg_manager
runtime_cmd="$1"
if [ "$MODE" = "cli" ] || [ "$REQUESTED_RUNTIME" = "skip" ]; then
printf 'none\n'
return
fi
if [ -n "$runtime_cmd" ]; then
printf 'none (using existing %s)\n' "$runtime_cmd"
return
fi
preferred_runtime="$(choose_runtime_preference)"
case "$OS_NAME:$preferred_runtime" in
darwin:docker)
printf 'docker, colima via Homebrew\n'
;;
darwin:podman)
printf 'podman via Homebrew\n'
;;
linux:docker)
pkg_manager="$(detect_linux_pkg_manager || true)"
case "$pkg_manager" in
apt-get)
printf 'docker.io via apt-get\n'
;;
dnf)
printf 'docker via dnf\n'
;;
yum)
printf 'docker via yum\n'
;;
*)
printf 'docker required (install manually)\n'
;;
esac
;;
linux:podman)
pkg_manager="$(detect_linux_pkg_manager || true)"
case "$pkg_manager" in
apt-get)
printf 'podman, uidmap, slirp4netns via apt-get\n'
;;
dnf)
printf 'podman via dnf\n'
;;
yum)
printf 'podman via yum\n'
;;
*)
printf 'podman required (install manually)\n'
;;
esac
;;
*)
printf 'none\n'
;;
esac
}
ensure_homebrew() {
if ! has_cmd brew; then
die "Homebrew is required on macOS when Python or a container runtime must be installed automatically."
fi
}
install_python() {
step "Installing Python 3.10+"
case "$OS_NAME" in
darwin)
ensure_homebrew
brew install python
;;
linux)
local pkg_manager
pkg_manager="$(detect_linux_pkg_manager)" || die \
"No supported Linux package manager found. Install Python 3.10+ manually and re-run the installer."
case "$pkg_manager" in
apt-get)
run_as_root apt-get update
run_as_root apt-get install -y python3 python3-venv python3-pip
;;
dnf)
run_as_root dnf install -y python3 python3-pip
;;
yum)
run_as_root yum install -y python3 python3-pip
;;
esac
;;
esac
done_step "Python 3.10+ is ready"
}
create_launcher() {
local launcher_path runtime_env_path executable_path
launcher_path="$BIN_DIR/vllm-sr"
runtime_env_path="$INSTALL_ROOT/runtime.env"
executable_path="$INSTALL_ROOT/venv/bin/vllm-sr"
mkdir -p "$BIN_DIR"
cat >"$launcher_path" <<EOF
#!/usr/bin/env bash
set -euo pipefail
if [ -f "$runtime_env_path" ]; then
# shellcheck disable=SC1090
. "$runtime_env_path"
fi
exec "$executable_path" "\$@"
EOF
chmod +x "$launcher_path"
}
install_cli() {
local python_cmd
python_cmd="$(find_python)" || {
info "Python 3.10+ was not found. The installer will add it now."
install_python
python_cmd="$(find_python)" || die "Unable to locate a Python 3.10+ interpreter after installation."
}
done_step "Using Python interpreter: $python_cmd"
mkdir -p "$INSTALL_ROOT"
step "Creating isolated environment at $INSTALL_ROOT/venv"
"$python_cmd" -m venv "$INSTALL_ROOT/venv"
done_step "Created isolated environment"
run_quiet_step \
"Bootstrapping installer Python tooling" \
"$INSTALL_ROOT/venv/bin/python" -m pip install --disable-pip-version-check --upgrade --quiet pip setuptools wheel
run_quiet_step \
"Installing vLLM Semantic Router from $PIP_SPEC" \
"$INSTALL_ROOT/venv/bin/python" -m pip install --disable-pip-version-check --upgrade --quiet "$PIP_SPEC"
step "Writing launcher to $BIN_DIR/vllm-sr"
create_launcher
done_step "Launcher is ready"
local version_output
version_output="$("$BIN_DIR/vllm-sr" --version 2>/dev/null || true)"
if [ -n "$version_output" ]; then
done_step "Installed $version_output"
else
done_step "Installed vllm-sr"
fi
}
docker_ready() {
has_cmd docker && docker info >/dev/null 2>&1
}
podman_ready() {
has_cmd podman && podman info >/dev/null 2>&1
}
choose_runtime_preference() {
if [ "$REQUESTED_RUNTIME" != "auto" ]; then
printf '%s\n' "$REQUESTED_RUNTIME"
return
fi
case "$OS_NAME" in
darwin)
printf 'docker\n'
;;
linux)
printf 'podman\n'
;;
esac
}
install_macos_docker_runtime() {
ensure_homebrew
step "Installing Docker CLI and Colima via Homebrew"
brew install docker colima
step "Starting Colima"
colima start
done_step "Docker + Colima runtime is ready"
}
install_macos_podman_runtime() {
ensure_homebrew
step "Installing Podman via Homebrew"
brew install podman
if ! podman machine inspect >/dev/null 2>&1; then
step "Initializing Podman machine"
podman machine init
fi
step "Starting Podman machine"
podman machine start
done_step "Podman runtime is ready"
}
install_linux_podman_runtime() {
local pkg_manager
pkg_manager="$(detect_linux_pkg_manager)" || die \
"No supported Linux package manager found. Install Podman manually and re-run the installer."
step "Installing Podman"
case "$pkg_manager" in
apt-get)
run_as_root apt-get update
run_as_root apt-get install -y podman uidmap slirp4netns
;;
dnf)
run_as_root dnf install -y podman
;;
yum)
run_as_root yum install -y podman
;;
esac
done_step "Podman runtime is ready"
}
install_linux_docker_runtime() {
local pkg_manager
pkg_manager="$(detect_linux_pkg_manager)" || die \
"No supported Linux package manager found. Install Docker manually and re-run the installer."
step "Installing Docker"
case "$pkg_manager" in
apt-get)
run_as_root apt-get update
run_as_root apt-get install -y docker.io
;;
dnf)
run_as_root dnf install -y docker
;;
yum)
run_as_root yum install -y docker
;;
esac
if has_cmd systemctl; then
run_as_root systemctl enable --now docker || true
fi
if [ "$(id -u)" -ne 0 ]; then
run_as_root usermod -aG docker "$USER" || true
fi
done_step "Docker runtime is ready"
}
write_runtime_env() {
local runtime_env_path
runtime_env_path="$INSTALL_ROOT/runtime.env"
case "$SELECTED_RUNTIME" in
podman)
printf 'export CONTAINER_RUNTIME=podman\n' >"$runtime_env_path"
;;
docker|'')
rm -f "$runtime_env_path"
;;
esac
}
ensure_runtime() {
if [ "$MODE" = "cli" ] || [ "$REQUESTED_RUNTIME" = "skip" ]; then
SELECTED_RUNTIME=""
write_runtime_env
info "Runtime bootstrap skipped."
return
fi
if docker_ready; then
SELECTED_RUNTIME="docker"
write_runtime_env
done_step "Using existing Docker runtime"
return
fi
if podman_ready; then
SELECTED_RUNTIME="podman"
write_runtime_env
done_step "Using existing Podman runtime"
return
fi
case "$(choose_runtime_preference)" in
docker)
case "$OS_NAME" in
darwin)
install_macos_docker_runtime
docker_ready || die "Docker is installed but not reachable. Try running 'colima start' and then 'vllm-sr serve'."
SELECTED_RUNTIME="docker"
;;
linux)
install_linux_docker_runtime
if docker_ready; then
SELECTED_RUNTIME="docker"
else
die "Docker was installed but is not reachable from the current shell. Open a new shell or run 'newgrp docker', then start with 'vllm-sr serve'."
fi
;;
esac
;;
podman)
case "$OS_NAME" in
darwin)
install_macos_podman_runtime
podman_ready || die "Podman is installed but not reachable. Try running 'podman machine start' and then 'vllm-sr serve'."
;;
linux)
install_linux_podman_runtime
podman_ready || die "Podman is installed but not reachable from the current shell."
;;
esac
SELECTED_RUNTIME="podman"
;;
*)
die "Unsupported runtime selection: $(choose_runtime_preference)"
;;
esac
write_runtime_env
}
launch_first_session() {
local launch_dir serve_log_file
if ! should_auto_launch; then
return
fi
LAUNCH_PLATFORM="$(resolve_launch_platform)"
launch_dir="$(resolve_launch_dir)"
if [ -n "$LAUNCH_PLATFORM" ]; then
info "First-run serve command: vllm-sr serve --platform $LAUNCH_PLATFORM"
else
info "First-run serve command: vllm-sr serve"
fi
info "First-run dashboard command: vllm-sr dashboard"
info "Starting the first local session. This can take a few minutes on the first image pull."
step "Running first-time serve flow"
serve_log_file="$(make_temp_log)"
if (
cd "$launch_dir"
if [ -n "$LAUNCH_PLATFORM" ]; then
"$BIN_DIR/vllm-sr" serve --platform "$LAUNCH_PLATFORM"
else
"$BIN_DIR/vllm-sr" serve
fi
) >"$serve_log_file" 2>&1; then
rm -f "$serve_log_file"
AUTO_LAUNCH_RAN="1"
done_step "First-time serve flow completed"
else
warn "Automatic first run did not complete. Command output follows:"
cat "$serve_log_file" >&2
rm -f "$serve_log_file"
warn "Automatic first run did not complete. Retry with:"
print_restart_command
die "Installation finished, but the first vllm-sr serve run failed"
fi
step "Checking dashboard availability"
if "$BIN_DIR/vllm-sr" dashboard --no-open >/dev/null 2>&1; then
done_step "Dashboard is available"
else
warn "The dashboard command could not confirm a running session."
print_dashboard_access
die "Installation finished, but the dashboard did not come up cleanly"
fi
step "Opening dashboard"
if open_dashboard_url; then
done_step "Dashboard opened in your browser"
else
warn "Could not open a browser automatically."
done_step "Dashboard is running"
print_dashboard_access
fi
}
print_path_hint() {
local shell_path_placeholder
shell_path_placeholder="$(printf '%s' "\$PATH")"
case ":$PATH:" in
*":$BIN_DIR:"*)
return 1
;;
*)
warn "$BIN_DIR is not on PATH."
printf '%b\n' "${COLOR_WHITE}Current shell${COLOR_RESET}"
printf ' export PATH="%s:%s"\n' "$BIN_DIR" "$shell_path_placeholder"
printf '\n'
return 0
;;
esac
}
print_next_steps() {
local primary_ip host_label
printf '\n'
done_step "vLLM Semantic Router is ready"
if [ -z "$LAUNCH_PLATFORM" ]; then
LAUNCH_PLATFORM="$(resolve_launch_platform)"
fi
if print_path_hint; then
info "Add the PATH export above before running vllm-sr."
fi
printf '%b\n' "${COLOR_WHITE}Ready${COLOR_RESET}"
if [ "$MODE" = "serve" ]; then
printf ' runtime %s\n' "${SELECTED_RUNTIME:-not configured}"
fi
if [ "$AUTO_LAUNCH_RAN" = "1" ]; then
primary_ip="$(detect_primary_ip || true)"
printf ' dashboard %s\n' "$DASHBOARD_URL"
if [ -n "$primary_ip" ]; then
printf ' network http://%s:8700\n' "$primary_ip"
fi
printf ' stop vllm-sr stop\n'
if [ -n "$LAUNCH_PLATFORM" ]; then
printf ' restart vllm-sr serve --platform %s\n' "$LAUNCH_PLATFORM"
else
printf ' restart vllm-sr serve\n'
fi
if is_remote_session; then
host_label="$(detect_host_label)"
printf ' tunnel ssh -L 8700:localhost:8700 %s@%s\n' "${USER:-user}" "$host_label"
fi
else
printf ' verify vllm-sr --version\n'
if [ "$MODE" = "serve" ]; then
if [ -n "$LAUNCH_PLATFORM" ]; then
printf ' start vllm-sr serve --platform %s\n' "$LAUNCH_PLATFORM"
else
printf ' start vllm-sr serve\n'
fi
printf ' open vllm-sr dashboard\n'
if [ "$SELECTED_RUNTIME" = "podman" ]; then
printf ' runtime env %s/runtime.env\n' "$INSTALL_ROOT"
fi
fi
fi
printf '\n'
}
parse_args() {
while [ "$#" -gt 0 ]; do
case "$1" in
--mode)
[ "$#" -ge 2 ] || die "Missing value for --mode"
MODE="$2"
shift 2
;;
--runtime)
[ "$#" -ge 2 ] || die "Missing value for --runtime"
REQUESTED_RUNTIME="$2"
shift 2
;;
--install-root)
[ "$#" -ge 2 ] || die "Missing value for --install-root"
INSTALL_ROOT="$2"
shift 2
;;
--bin-dir)
[ "$#" -ge 2 ] || die "Missing value for --bin-dir"
BIN_DIR="$2"
shift 2
;;
--pip-spec)
[ "$#" -ge 2 ] || die "Missing value for --pip-spec"
PIP_SPEC="$2"
shift 2
;;
--python)
[ "$#" -ge 2 ] || die "Missing value for --python"
PYTHON_BIN="$2"
shift 2
;;
--platform)
[ "$#" -ge 2 ] || die "Missing value for --platform"
REQUESTED_PLATFORM="$2"
shift 2
;;
--no-launch)
AUTO_LAUNCH="0"
shift
;;