Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

fix(install): align LiveKit RTC ports after reassignment

Dongdong Chen997a831c51ae
diff --git a/.env.example b/.env.example
index aa2902c8..db21a39e 100644
--- a/.env.example
+++ b/.env.example
@@ -130,6 +130,10 @@ VOICE_RUNTIME_XAI_LIVE_AUDIO_TRANSPORT=binary
LIVEKIT_URL=ws://127.0.0.1:17880
LIVEKIT_API_KEY=devkey
LIVEKIT_API_SECRET=devsecret-livekit-voice-local-only-32-bytes
+# Compose ports. RTC ports must match the ports LiveKit advertises to browsers.
+LIVEKIT_HTTP_PORT=17880
+LIVEKIT_RTC_TCP_PORT=7881
+LIVEKIT_RTC_UDP_PORT=7882
# The root docker-compose.yml LiveKit serves this computer only. A host that
# serves browsers on other computers sets the address they reach it on,
# publishes the media ports (TCP 7881, UDP 7882) on every interface, and sets
diff --git a/README.md b/README.md
index 0f418c68..df0df5b8 100644
--- a/README.md
+++ b/README.md
@@ -207,6 +207,10 @@ approval, and connects `linger-computer` to your Linger server. Run
`--remove`), or see [Bring your own runtime](docs/local-inference.md) for other
model setups.
+If Compose ports are busy, the installer offers to save free ports in `.env`.
+LiveKit uses the selected RTC ports both inside its container and on the host,
+so browsers connect to the ports it advertises.
+
## Learn more
The full documentation lives at **[docs.heylinger.com](https://docs.heylinger.com/)**.
diff --git a/docker-compose.yml b/docker-compose.yml
index acf1267b..28802c44 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -57,8 +57,8 @@ services:
- |
port: 7880
rtc:
- tcp_port: 7881
- udp_port: 7882
+ tcp_port: ${LIVEKIT_RTC_TCP_PORT:-7881}
+ udp_port: ${LIVEKIT_RTC_UDP_PORT:-7882}
use_external_ip: false
logging:
level: info
@@ -71,9 +71,9 @@ services:
# ports with LIVEKIT_RTC_BIND_ADDRESS.
NODE_IP: "${LIVEKIT_NODE_IP:-127.0.0.1}"
ports:
- - "127.0.0.1:17880:7880"
- - "${LIVEKIT_RTC_BIND_ADDRESS:-127.0.0.1}:7881:7881"
- - "${LIVEKIT_RTC_BIND_ADDRESS:-127.0.0.1}:7882:7882/udp"
+ - "127.0.0.1:${LIVEKIT_HTTP_PORT:-17880}:7880"
+ - "${LIVEKIT_RTC_BIND_ADDRESS:-127.0.0.1}:${LIVEKIT_RTC_TCP_PORT:-7881}:${LIVEKIT_RTC_TCP_PORT:-7881}"
+ - "${LIVEKIT_RTC_BIND_ADDRESS:-127.0.0.1}:${LIVEKIT_RTC_UDP_PORT:-7882}:${LIVEKIT_RTC_UDP_PORT:-7882}/udp"
healthcheck:
test: ["CMD", "wget", "-q", "-O", "-", "http://127.0.0.1:7880/"]
interval: 3s
diff --git a/scripts/env-inventory.json b/scripts/env-inventory.json
index 399142b2..455b4a17 100644
--- a/scripts/env-inventory.json
+++ b/scripts/env-inventory.json
@@ -9,6 +9,9 @@
"WEB_BIND_ADDRESS": "docker compose host-address interpolation of the Web port in the root docker-compose.yml (pnpm stack:up)",
"NODE_SERVICES_HTTP_PORT": "docker compose host-port interpolation in the root docker-compose.yml (pnpm stack:up)",
"DOCUMENT_RUNTIME_HTTP_PORT": "docker compose host-port interpolation in the root docker-compose.yml (pnpm stack:up)",
+ "LIVEKIT_HTTP_PORT": "docker compose host-port interpolation of the LiveKit HTTP endpoint in the root docker-compose.yml",
+ "LIVEKIT_RTC_TCP_PORT": "docker compose interpolation of both the published TCP port and LiveKit RTC TCP listener in the root docker-compose.yml",
+ "LIVEKIT_RTC_UDP_PORT": "docker compose interpolation of both the published UDP port and LiveKit RTC UDP listener in the root docker-compose.yml",
"LIVEKIT_NODE_IP": "docker compose interpolation of the LiveKit advertised media address (NODE_IP) in the root docker-compose.yml",
"LIVEKIT_RTC_BIND_ADDRESS": "docker compose host-address interpolation of the LiveKit media ports in the root docker-compose.yml"
},
diff --git a/scripts/install.test.ts b/scripts/install.test.ts
index be994e5a..184f0b74 100644
--- a/scripts/install.test.ts
+++ b/scripts/install.test.ts
@@ -753,7 +753,7 @@ describe("root install.sh", () => {
expect(await readdir(privateTmp)).toEqual([]);
});
- it("reassigns colliding Docker Compose ports and configures LiveKit override", async () => {
+ it("reassigns colliding Compose ports and preserves LiveKit RTC ports on rerun", async () => {
const root = await createTempRoot();
const fakeRepo = path.join(root, "fake-repo");
const fakeBin = path.join(root, "fake-bin");
@@ -867,22 +867,34 @@ esac
expect(updatedEnv).toContain("WEB_HTTP_PORT=3001");
expect(updatedEnv).toContain("WEB_PUBLIC_ORIGIN=http://localhost:3001");
expect(updatedEnv).toContain("LIVEKIT_URL=ws://127.0.0.1:17881");
- expect(updatedEnv).toContain(
- "COMPOSE_FILE=docker-compose.yml:.local/compose.ports.yml",
- );
+ expect(updatedEnv).toContain("LIVEKIT_HTTP_PORT=17881");
+ expect(updatedEnv).toContain("LIVEKIT_RTC_TCP_PORT=7883");
+ expect(updatedEnv).toContain("LIVEKIT_RTC_UDP_PORT=7884");
+ expect(updatedEnv).not.toContain("COMPOSE_FILE=");
expect(updatedEnv).not.toContain("POSTGRES_PORT=5433");
-
- const portsOverride = await readFile(
- path.join(fakeRepo, ".local/compose.ports.yml"),
- "utf8",
- );
- expect(portsOverride).toContain("ports: !override");
- expect(portsOverride).toContain("127.0.0.1:17881:7880");
- expect(portsOverride).toContain("7883:7881");
- expect(portsOverride).toContain("7884:7882/udp");
+ await expect(
+ stat(path.join(fakeRepo, ".local/compose.ports.yml")),
+ ).rejects.toMatchObject({ code: "ENOENT" });
const dockerCalls = await readFile(dockerLogPath, "utf8");
expect(dockerCalls).toContain("compose up --build --detach --wait");
+
+ const repeated = await runInstallScript([], {
+ scriptPath: copiedInstallPath,
+ cwd: fakeRepo,
+ env: {
+ HOME: homeDir,
+ XDG_CACHE_HOME: xdgCache,
+ PATH: `${fakeBin}:/usr/local/bin:/usr/bin:/bin`,
+ LINGER_INSTALL_BUSY_PORTS: "3000,17880,7881,7882",
+ },
+ input: ["1", "n", "n", "n"].join("\n") + "\n",
+ });
+ expect(repeated.code).toBe(0);
+ expect(repeated.stdout).not.toContain("Port(s) already in use:");
+ expect(await readFile(path.join(fakeRepo, ".env"), "utf8")).toBe(
+ updatedEnv,
+ );
});
it("validates CLI flags, conflicting modes, and standalone menu outside repo", async () => {
diff --git a/scripts/install/install.sh b/scripts/install/install.sh
index 2a2d7506..055cd34e 100755
--- a/scripts/install/install.sh
+++ b/scripts/install/install.sh
@@ -426,20 +426,6 @@ collect_docker_host_ports() {
tr ', ' '\n' | sed -nE 's/.*:([0-9]+)->[0-9]+\/(tcp|udp).*/\1\/\2/p' | sort -u
}
-read_livekit_override_port() {
- local file="$1"
- local container_port="$2"
- local fallback="$3"
- [[ -f "$file" ]] || { printf '%s\n' "$fallback"; return 0; }
- local match=""
- match="$(sed -nE "s/.*:([0-9]+):${container_port}(\/udp)?\"?[[:space:]]*$/\1/p" "$file" | head -n 1)"
- if [[ -n "$match" ]]; then
- printf '%s\n' "$match"
- else
- printf '%s\n' "$fallback"
- fi
-}
-
is_port_busy() {
local port="$1"
local proto="$2"
@@ -503,7 +489,6 @@ pick_free_port() {
ensure_compose_ports() {
local env_file="$REPO_ROOT/.env"
- local override_file="$REPO_ROOT/.local/compose.ports.yml"
local own_raw=""
own_raw="$(cd "$REPO_ROOT" && docker compose ps --format '{{.Ports}}' 2>/dev/null || true)"
@@ -528,9 +513,9 @@ ensure_compose_ports() {
cur_node="$(read_env_value "$env_file" "NODE_SERVICES_HTTP_PORT" || printf '4319')"
cur_doc="$(read_env_value "$env_file" "DOCUMENT_RUNTIME_HTTP_PORT" || printf '4321')"
cur_lk_url="$(read_env_value "$env_file" "LIVEKIT_URL" || printf 'ws://127.0.0.1:17880')"
- cur_lk_http="$(read_livekit_override_port "$override_file" "7880" "17880")"
- cur_lk_tcp="$(read_livekit_override_port "$override_file" "7881" "7881")"
- cur_lk_udp="$(read_livekit_override_port "$override_file" "7882" "7882")"
+ cur_lk_http="$(read_env_value "$env_file" "LIVEKIT_HTTP_PORT" || printf '17880')"
+ cur_lk_tcp="$(read_env_value "$env_file" "LIVEKIT_RTC_TCP_PORT" || printf '7881')"
+ cur_lk_udp="$(read_env_value "$env_file" "LIVEKIT_RTC_UDP_PORT" || printf '7882')"
local reserved=" $cur_pg $cur_th $cur_web $cur_node $cur_doc $cur_lk_http $cur_lk_tcp $cur_lk_udp "
local new_pg="$cur_pg"
@@ -658,29 +643,17 @@ ensure_compose_ports() {
set_env_value "$env_file" "DOCUMENT_RUNTIME_HTTP_PORT" "$new_doc"
fi
- if [[ "$new_lk_http" != "17880" || "$new_lk_tcp" != "7881" || "$new_lk_udp" != "7882" ]]; then
+ if [[ "$new_lk_http" != "$cur_lk_http" ]]; then
+ set_env_value "$env_file" "LIVEKIT_HTTP_PORT" "$new_lk_http"
if [[ -z "$cur_lk_url" || "$cur_lk_url" =~ ^ws://(127\.0\.0\.1|localhost): ]]; then
set_env_value "$env_file" "LIVEKIT_URL" "ws://127.0.0.1:$new_lk_http"
fi
- mkdir -p "$REPO_ROOT/.local"
- cat <<EOF > "$override_file"
-services:
- livekit:
- ports: !override
- - "127.0.0.1:$new_lk_http:7880"
- - "\${LIVEKIT_RTC_BIND_ADDRESS:-127.0.0.1}:$new_lk_tcp:7881"
- - "\${LIVEKIT_RTC_BIND_ADDRESS:-127.0.0.1}:$new_lk_udp:7882/udp"
-EOF
- local cur_compose_file=""
- cur_compose_file="$(read_env_value "$env_file" "COMPOSE_FILE" || true)"
- cur_compose_file="${cur_compose_file//.linger-runtime\/compose.ports.yml/}"
- cur_compose_file="${cur_compose_file#:}"
- cur_compose_file="${cur_compose_file%:}"
- if [[ -z "$cur_compose_file" ]]; then
- set_env_value "$env_file" "COMPOSE_FILE" "docker-compose.yml:.local/compose.ports.yml"
- elif [[ ":$cur_compose_file:" != *":.local/compose.ports.yml:"* ]]; then
- set_env_value "$env_file" "COMPOSE_FILE" "$cur_compose_file:.local/compose.ports.yml"
- fi
+ fi
+ if [[ "$new_lk_tcp" != "$cur_lk_tcp" ]]; then
+ set_env_value "$env_file" "LIVEKIT_RTC_TCP_PORT" "$new_lk_tcp"
+ fi
+ if [[ "$new_lk_udp" != "$cur_lk_udp" ]]; then
+ set_env_value "$env_file" "LIVEKIT_RTC_UDP_PORT" "$new_lk_udp"
fi
}