Install Pipelines natively by default on macOS and Linux

Add scripts/setup-native.py and make ./install (and --native) build the server, the CLI
and ntfy from source into ~/.local/share/pipelines, detect an existing host OpenCode
and Pi instead of installing them, install the packaged authoring skill, migrate an
existing Docker database and ntfy auth store, save the host client default and start
both services. ./install --docker keeps the previous Docker server + ntfy
installation unchanged.

ntfy is compiled from its pinned Go module on every host because upstream publishes
no macOS server binary (its darwin asset is built with -tags noserver); its cgo
SQLite driver is why a C compiler is now required natively. The ntfy credential
bootstrap and the client default writer are shared by both installers,
installation.Load resolves symlinked prefixes, the Docker migration copies the
SQLite write-ahead log so the newest definitions and runs are not lost, and the
account subcommands read the generated configuration through NTFY_CONFIG_FILE.

Verified on macOS: 115 Python tests, go build/vet/test, and scratch installs that
migrate 9 pipelines and 31 runs, build ntfy v2.30.0 and start both services healthy
on spare ports before stopping them.
This commit is contained in:
2026-10-13 17:20:14 +01:00
parent 9b305df725
commit a70e3aef4b
21 changed files with 1474 additions and 153 deletions
+90 -16
View File
@@ -17,6 +17,15 @@ DEFAULT_PREFIX = Path.home() / ".local/share/pipelines"
MARKER = "pipelines-install.json"
def ntfy_mode(config):
"""Native ntfy is selected by the manifest; absent/explicit docker uses Compose."""
return (config.get("ntfy") or {}).get("mode", "docker")
def ntfy_health_url(config):
return f"http://127.0.0.1:{config['ntfy_port']}/v1/health"
def load(prefix):
prefix = Path(prefix).expanduser().resolve()
path = prefix / MARKER
@@ -60,19 +69,27 @@ def wait_health(url, timeout=40):
raise RuntimeError(f"Service did not become healthy: {url}; see pipelines logs")
def process_command(pid):
"""Return the OS command line for a live PID, or None when it cannot be read."""
try:
return subprocess.check_output(["ps", "-p", str(pid), "-o", "command="], text=True)
except (OSError, subprocess.CalledProcessError):
return None
def managed_pid(config):
path = Path(config["prefix"]) / "supervisor.pid"
try:
pid = int(path.read_text())
if pid <= 1:
return None
command = subprocess.check_output(["ps", "-p", str(pid), "-o", "command="], text=True)
# Never signal an arbitrary/reused PID.
if str(Path(config["prefix"]) / "lib/manage.py") not in command or "supervise" not in command:
return None
return pid
except (OSError, ValueError, subprocess.CalledProcessError):
except (OSError, ValueError):
return None
if pid <= 1:
return None
command = process_command(pid)
# Never signal an arbitrary/reused PID.
if command is None or str(Path(config["prefix"]) / "lib/manage.py") not in command or "supervise" not in command:
return None
return pid
def registration(config):
@@ -112,7 +129,48 @@ def stop(config):
time.sleep(0.2)
if managed_pid(config) is not None:
raise RuntimeError("Supervisor did not stop; inspect logs before trying again")
compose(config, "stop", "ntfy", quiet=True)
if ntfy_mode(config) == "native":
ntfy_stop(config)
else:
compose(config, "stop", "ntfy", quiet=True)
def ntfy_start(config):
info = config["ntfy"]
log = (Path(config["prefix"]) / "logs/ntfy.log").open("a")
child = subprocess.Popen([info["bin"], "serve", "--config", info["config"]],
stdin=subprocess.DEVNULL, stdout=log, stderr=log, start_new_session=True)
log.close()
(Path(config["prefix"]) / "ntfy.pid").write_text(str(child.pid))
return child
def ntfy_stop(config):
path = Path(config["prefix"]) / "ntfy.pid"
try:
pid = int(path.read_text())
except (OSError, ValueError):
return
if pid <= 1:
return
command = process_command(pid)
# Never signal an arbitrary/reused PID: only the managed ntfy serve process.
# Accept the recorded path or its symlink-resolved form so a prefix reached
# through a symlinked HOME (macOS /var → /private/var) is still matched.
binary = str(config["ntfy"]["bin"])
candidates = {binary, str(Path(binary).resolve())}
if command is None or "serve" not in command or not any(candidate in command for candidate in candidates):
path.unlink(missing_ok=True)
return
os.kill(pid, signal.SIGTERM)
deadline = time.monotonic() + 10
while time.monotonic() < deadline:
try:
os.kill(pid, 0)
except ProcessLookupError:
break
time.sleep(0.1)
path.unlink(missing_ok=True)
def supervise(config):
@@ -126,18 +184,23 @@ def supervise(config):
pidfile.write_text(str(os.getpid()))
stopped = False
child = None
ntfy_child = None
def stopping(*_):
nonlocal stopped
stopped = True
if child is not None and child.poll() is None:
child.terminate()
for process in (child, ntfy_child):
if process is not None and process.poll() is None:
process.terminate()
signal.signal(signal.SIGTERM, stopping)
signal.signal(signal.SIGINT, stopping)
try:
compose(config, "up", "-d", "ntfy", quiet=True)
wait_health(f"http://127.0.0.1:{config['ntfy_port']}/v1/health")
if ntfy_mode(config) == "native":
ntfy_child = ntfy_start(config)
else:
compose(config, "up", "-d", "ntfy", quiet=True)
wait_health(ntfy_health_url(config))
if stopped:
return
env = dict(os.environ)
@@ -163,7 +226,17 @@ def supervise(config):
except subprocess.TimeoutExpired:
child.kill()
child.wait()
compose(config, "stop", "ntfy", quiet=True, check=False)
if ntfy_mode(config) == "native":
if ntfy_child is not None and ntfy_child.poll() is None:
ntfy_child.terminate()
try:
ntfy_child.wait(timeout=10)
except subprocess.TimeoutExpired:
ntfy_child.kill()
ntfy_child.wait()
(root / "ntfy.pid").unlink(missing_ok=True)
else:
compose(config, "stop", "ntfy", quiet=True, check=False)
pidfile.unlink(missing_ok=True)
@@ -178,7 +251,8 @@ def uninstall(config, purge=False, yes=False):
if platform.system() != "Darwin":
run(["systemctl", "--user", "disable", config["label"] + ".service"], quiet=True, check=False)
Path(registration(config)).unlink(missing_ok=True)
compose(config, "down", *(["--volumes"] if purge else []), quiet=True)
if ntfy_mode(config) != "native":
compose(config, "down", *(["--volumes"] if purge else []), quiet=True)
link = Path(config["launcher"])
if link.is_symlink() and link.resolve() == (root / "bin/pipelines").resolve():
if str(link)=="/usr/local/bin/pipelines" and not os.access(link.parent,os.W_OK):
@@ -231,7 +305,7 @@ def main():
stop(config); start(config)
elif args.action in ("status", "doctor"):
print("Pipeline server:", "healthy" if healthy(f"http://127.0.0.1:{config['server_port']}/healthz") else "stopped/unhealthy")
print("ntfy:", "healthy" if healthy(f"http://127.0.0.1:{config['ntfy_port']}/v1/health") else "stopped/unhealthy")
print("ntfy:", "healthy" if healthy(ntfy_health_url(config)) else "stopped/unhealthy")
print("Phone server:", config["public_url"], "· topic:", config["topic"], "· username:", config["username"])
if args.action == "doctor":
run([config["opencode"], "api", "get", "/api/info"], quiet=True)