Bind the native server to the LAN so the phone client can reach it

The native install hardcoded -addr 127.0.0.1, so the server was unreachable from
the phone: the emulator worked because it proxies to the host loopback, but a
real device could not connect even though ntfy (bound to 0.0.0.0:8090) worked.

The bind address is now a manifest setting (server_address() in manage.py, with
older manifests still defaulting to loopback) and setup-native.py records it,
defaulting to 0.0.0.0 like the Docker install did and offering
--bind-address 127.0.0.1 for a loopback-only server. An invalid address is
rejected, and setup prints the phone client URL.

Verified: scripts test suite 116 tests OK, and after reinstalling the server
listens on *:8080 and answers {"healthy":true} on 127.0.0.1, 10.0.0.75,
10.0.0.249 and the tailnet address.
This commit is contained in:
2026-10-15 01:57:27 +01:00
parent 9ca775291b
commit 8adc6b8080
5 changed files with 48 additions and 6 deletions
+10 -1
View File
@@ -26,6 +26,15 @@ def ntfy_health_url(config):
return f"http://127.0.0.1:{config['ntfy_port']}/v1/health"
def server_address(config):
"""The -addr the server binds.
The bind address is a manifest setting so the phone client can reach the
server over the LAN; manifests written before it existed default to loopback.
"""
return f"{config.get('bind_address') or '127.0.0.1'}:{config['server_port']}"
def load(prefix):
prefix = Path(prefix).expanduser().resolve()
path = prefix / MARKER
@@ -212,7 +221,7 @@ def supervise(config):
env.pop("PIPELINES_NTFY_TOKEN", None)
with (root / "logs/server.log").open("a") as log:
child = subprocess.Popen([str(root / "bin/pipelines-server"), "-addr",
f"127.0.0.1:{config['server_port']}", "-db", str(root / "data/pipelines.db")],
server_address(config), "-db", str(root / "data/pipelines.db")],
cwd=config["workspace"], env=env, stdout=log, stderr=log)
while child.poll() is None and not stopped:
time.sleep(0.25)
+22 -1
View File
@@ -13,6 +13,7 @@ invented here.
"""
import argparse
import importlib.util
import ipaddress
import json
import os
import shutil
@@ -47,6 +48,11 @@ C_COMPILERS = ("cc", "clang", "gcc")
NTFY_BUILD_TAGS = "sqlite_omit_load_extension,osusergo,netgo"
DEFAULT_NTFY_PORT = 8090
DEFAULT_SERVER_PORT = 8080
# The phone client reaches the server over the LAN, matching the Docker install
# (which published 0.0.0.0). Use --bind-address 127.0.0.1 for a loopback-only
# server; the Pipelines API has no authentication, so keep it on a trusted
# LAN/VPN either way.
DEFAULT_BIND_ADDRESS = "0.0.0.0"
class Setup:
@@ -360,6 +366,10 @@ class Setup:
raise ValueError("Invalid ntfy port; choose a value between 1024 and 65535")
if args.ntfy_port == args.port:
raise ValueError("The server and ntfy ports must differ")
try:
ipaddress.IPv4Address(args.bind_address)
except ValueError:
raise ValueError("Invalid bind address; use an IPv4 address such as 0.0.0.0 or 127.0.0.1") from None
prefix = self.resolve_prefix()
self.prepare_layout(prefix)
harness = self.harness()
@@ -372,7 +382,8 @@ class Setup:
resolution = self.resolve_ntfy()
self.build(prefix)
self.install_skill(prefix)
base_url = args.ntfy_url or f"http://{lan.detect_lan()}:{args.ntfy_port}"
lan_ip = lan.detect_lan()
base_url = args.ntfy_url or f"http://{lan_ip}:{args.ntfy_port}"
config_path = self.write_ntfy_config(prefix, base_url, args.ntfy_port)
self.build_ntfy(prefix, resolution)
# Migrate existing Docker data before creating native ntfy accounts so a
@@ -399,6 +410,7 @@ class Setup:
"prefix": str(prefix),
"python": python,
"server_port": args.port,
"bind_address": args.bind_address,
"ntfy_port": args.ntfy_port,
"opencode": harness["opencode"],
"pi": harness["pi"],
@@ -438,6 +450,12 @@ class Setup:
f"'{prefix}/bin/pipelines start' to see the error. Check that ports "
f"{args.port} and {args.ntfy_port} are free (a running Docker installation uses them).")
print(f"ntfy is configured for {base_url} and both services are running.")
if args.bind_address == "0.0.0.0":
print(f"Phone client server URL: ws://{lan_ip}:{args.port}/connect "
"(use a workspace path that exists on this server).")
else:
print(f"Server bound to {args.bind_address}:{args.port}; a phone on the LAN needs a LAN bind "
"(re-run with --bind-address 0.0.0.0).")
print("Create the phone account password if it is a new account, then subscribe to the pipelines topic.")
@@ -447,6 +465,9 @@ def arguments(argv=None):
parser.add_argument("--ntfy-url", help="Override the auto-detected LAN ntfy address")
parser.add_argument("--timezone", help="Override the detected timezone (fallback: UTC)")
parser.add_argument("--port", type=int, default=DEFAULT_SERVER_PORT, help="Pipelines server port")
parser.add_argument("--bind-address", default=DEFAULT_BIND_ADDRESS,
help="Server bind address (default 0.0.0.0, the LAN, so the phone client can reach it; "
"use 127.0.0.1 for a loopback-only server)")
parser.add_argument("--ntfy-port", type=int, default=DEFAULT_NTFY_PORT, help="ntfy listen port")
parser.add_argument("--model", help="Record an explicit default model; otherwise host OpenCode configuration is reused")
parser.add_argument("--replace-data", action="store_true",
+7
View File
@@ -37,6 +37,13 @@ class ManageNativeTests(unittest.TestCase):
self.assertEqual(manage.ntfy_mode({"ntfy": {"mode": "native"}}), "native")
self.assertEqual(manage.ntfy_health_url({"ntfy_port": 8090}), "http://127.0.0.1:8090/v1/health")
def test_server_address_uses_the_manifest_bind_and_defaults_to_loopback(self):
self.assertEqual(manage.server_address({"server_port": 8080, "bind_address": "0.0.0.0"}), "0.0.0.0:8080")
self.assertEqual(manage.server_address({"server_port": 8080, "bind_address": "10.0.0.75"}), "10.0.0.75:8080")
# A manifest written before the setting existed must stay loopback-only.
self.assertEqual(manage.server_address({"server_port": 8080}), "127.0.0.1:8080")
self.assertEqual(manage.server_address({"server_port": 8080, "bind_address": ""}), "127.0.0.1:8080")
def test_ntfy_start_launches_binary_with_generated_config(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
+1
View File
@@ -173,6 +173,7 @@ class SetupNativeTests(unittest.TestCase):
self.assertEqual(config["format"], 1)
self.assertEqual(config["prefix"], str(prefix.resolve()))
self.assertEqual(config["server_port"], 8080)
self.assertEqual(config["bind_address"], "0.0.0.0")
self.assertEqual(config["ntfy"]["mode"], "native")
self.assertEqual(config["topic"], "pipelines")
self.assertEqual(config["opencode"], "/usr/bin/opencode")