Remove ntfy: notifications go only through the app notification stream
Server: drop ntfy publishing (stage hooks, run outbox, chat attention, chat tool notify, auto-switch and schedule notices), the chat push outbox (its table is dropped at startup), ntfy status/endpoints and PIPELINES_NTFY_*. The app_notifications stream, subscribe/clear and kinds are unchanged. Notification settings keep run_finished/chat_needs_you/chat_reply_finished; ntfy_enabled is accepted and ignored and its stored row is never read. Stage type=ntfy is rejected: "ntfy stages were removed; notifications go to the Pipelines apps — use the stage notify hook". The notify hook remains. Installer: no ntfy build, accounts, config or supervisor child; manifest gets top-level "mode" (legacy ntfy.mode still read). Reinstall retires an old ntfy (safe PID-file stop, deletes binary, config, data dir, token, log, with a note in logs/install.log); uninstall cleans leftovers. App: ntfy settings section replaced by "Notification events"; texts updated. Docs: docs/ntfy.md folded into docs/notifications.md; install, docker, cli, author skill references updated; security review M1 marked resolved. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+101
-75
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
"""One per-user lifecycle for the server, authenticated web proxy and ntfy."""
|
||||
"""One per-user lifecycle for the server and the authenticated web proxy."""
|
||||
import argparse
|
||||
import fcntl
|
||||
import json
|
||||
@@ -20,13 +20,12 @@ MARKER = "pipelines-install.json"
|
||||
SERVICE_MARKER = "Managed by Pipelines native installer"
|
||||
|
||||
|
||||
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 install_mode(config):
|
||||
""""native" for the native installer's manifest, else "docker".
|
||||
|
||||
|
||||
def ntfy_health_url(config):
|
||||
return f"http://127.0.0.1:{config['ntfy_port']}/v1/health"
|
||||
Manifests record a top-level "mode"; ones written before it marked a native
|
||||
install with ntfy.mode, which is still accepted until the next ./install."""
|
||||
return config.get("mode") or (config.get("ntfy") or {}).get("mode") or "docker"
|
||||
|
||||
|
||||
def server_address(config):
|
||||
@@ -84,7 +83,7 @@ def load(prefix):
|
||||
def run(args, *, env=None, quiet=False, check=True, timeout=120):
|
||||
result = subprocess.run(args, env=env, capture_output=True, text=True, timeout=timeout)
|
||||
if check and result.returncode:
|
||||
# No subprocess output here: ntfy token/password commands may contain secrets.
|
||||
# No subprocess output here: tool output may contain secrets.
|
||||
raise RuntimeError(f"Command failed ({result.returncode}): {args[0]} {args[1] if len(args)>1 else ''}")
|
||||
if not quiet and result.stdout:
|
||||
print(result.stdout.rstrip())
|
||||
@@ -142,7 +141,7 @@ def registration(config):
|
||||
|
||||
def service_command(config, arguments):
|
||||
parser = argparse.ArgumentParser(prog="pipelines service",
|
||||
description="Manage this native installation's server, authenticated web and ntfy login service.")
|
||||
description="Manage this native installation's server and authenticated web login service.")
|
||||
parser.add_argument("action", choices=("enable", "disable", "status"))
|
||||
parser.add_argument("--print", dest="preview", action="store_true",
|
||||
help="Preview enable's existing service definition without changing or starting anything")
|
||||
@@ -152,7 +151,7 @@ def service_command(config, arguments):
|
||||
args = parser.parse_args(arguments)
|
||||
if args.preview and args.action != "enable":
|
||||
parser.error("--print is only supported with enable")
|
||||
if ntfy_mode(config) != "native" or config.get("label") != "net.a-wan.pipelines" or not registration(config):
|
||||
if install_mode(config) != "native" or config.get("label") != "net.a-wan.pipelines" or not registration(config):
|
||||
raise ValueError("No native installer login service is recorded; rerun ./install")
|
||||
path = Path(registration(config))
|
||||
if platform.system() == "Darwin":
|
||||
@@ -186,7 +185,7 @@ def service_command(config, arguments):
|
||||
print(content, end="")
|
||||
elif args.action == "enable":
|
||||
start(config)
|
||||
print("Native login autostart enabled: server, authenticated web and ntfy.")
|
||||
print("Native login autostart enabled: server and authenticated web.")
|
||||
elif args.action == "disable":
|
||||
if platform.system() == "Darwin":
|
||||
run(["launchctl", "disable", f"gui/{os.getuid()}/{config['label']}"], quiet=True)
|
||||
@@ -266,48 +265,93 @@ 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")
|
||||
if ntfy_mode(config) == "native":
|
||||
ntfy_stop(config)
|
||||
else:
|
||||
compose(config, "stop", "ntfy", quiet=True)
|
||||
# Installs from before ntfy was removed ran it beside the server.
|
||||
stop_legacy_ntfy(config)
|
||||
|
||||
|
||||
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
|
||||
# --- retired ntfy ---------------------------------------------------------
|
||||
# Pipelines no longer runs ntfy: notifications reach the apps through the
|
||||
# server's own notification stream. Older installs left a supervised ntfy
|
||||
# process, its binary, configuration, data and publishing token behind; these
|
||||
# helpers stop and remove exactly those, idempotently.
|
||||
|
||||
def legacy_ntfy_pid(config):
|
||||
"""The PID in <prefix>/ntfy.pid while it is still the managed `ntfy serve`.
|
||||
|
||||
def ntfy_stop(config):
|
||||
path = Path(config["prefix"]) / "ntfy.pid"
|
||||
Never an arbitrary/reused PID: the command line must run <prefix>/bin/ntfy
|
||||
(or the binary the old manifest recorded, or a symlink-resolved form, so a
|
||||
prefix reached through a symlinked HOME such as macOS /var → /private/var
|
||||
still matches) with `serve`. A reaped or zombie process no longer matches."""
|
||||
root = Path(config["prefix"])
|
||||
try:
|
||||
pid = int(path.read_text())
|
||||
pid = int((root / "ntfy.pid").read_text())
|
||||
except (OSError, ValueError):
|
||||
return
|
||||
return None
|
||||
if pid <= 1:
|
||||
return
|
||||
return None
|
||||
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:
|
||||
binaries = {str(root / "bin/ntfy"), str((root / "bin/ntfy").resolve())}
|
||||
recorded = (config.get("ntfy") or {}).get("bin")
|
||||
if recorded:
|
||||
binaries.update((str(recorded), str(Path(recorded).resolve())))
|
||||
if command is None or "serve" not in command.split() or not any(binary in command for binary in binaries):
|
||||
return None
|
||||
return pid
|
||||
|
||||
|
||||
def stop_legacy_ntfy(config, timeout=10):
|
||||
"""Stops a leftover managed ntfy and forgets its PID file; True if one ran."""
|
||||
pid = legacy_ntfy_pid(config)
|
||||
if pid is not None:
|
||||
try:
|
||||
os.kill(pid, 0)
|
||||
os.kill(pid, signal.SIGTERM)
|
||||
except ProcessLookupError:
|
||||
break
|
||||
time.sleep(0.1)
|
||||
path.unlink(missing_ok=True)
|
||||
pid = None
|
||||
deadline = time.monotonic() + timeout
|
||||
while pid is not None and legacy_ntfy_pid(config) == pid and time.monotonic() < deadline:
|
||||
time.sleep(0.1)
|
||||
if pid is not None and legacy_ntfy_pid(config) == pid:
|
||||
try:
|
||||
os.kill(pid, signal.SIGKILL)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
(Path(config["prefix"]) / "ntfy.pid").unlink(missing_ok=True)
|
||||
return pid is not None
|
||||
|
||||
|
||||
def legacy_ntfy_paths(root):
|
||||
"""Everything an older install created for ntfy under the prefix."""
|
||||
root = Path(root)
|
||||
return [root / "bin/ntfy", root / "ntfy.pid", root / "logs/ntfy.log",
|
||||
root / "data/ntfy", root / "secrets/publisher-token"]
|
||||
|
||||
|
||||
def retire_ntfy(config, note=print):
|
||||
"""Stops and removes an older install's ntfy; a no-op once it is gone.
|
||||
|
||||
``config`` is the old manifest (or any dict with "prefix"). Before anything
|
||||
is removed ``note`` receives a line naming what goes (paths and the old
|
||||
ntfy version, never credentials). Only the fixed paths under the prefix are
|
||||
removed, never paths read from the manifest. Returns the removed paths."""
|
||||
root = Path(config["prefix"])
|
||||
present = [path for path in legacy_ntfy_paths(root) if path.exists() or path.is_symlink()]
|
||||
legacy = config.get("ntfy") or {}
|
||||
if not present and not legacy:
|
||||
stop_legacy_ntfy(config)
|
||||
return []
|
||||
version = legacy.get("version") or "unknown"
|
||||
note(f"Retiring ntfy (version {version}); Pipelines no longer uses it. Removing: "
|
||||
+ (", ".join(map(str, present)) or "nothing left on disk") + ".")
|
||||
if stop_legacy_ntfy(config):
|
||||
note("Stopped the old ntfy server process.")
|
||||
if install_mode(config) != "native" and (root / "compose.yaml").is_file() and config.get("docker") and config.get("project"):
|
||||
compose(config, "rm", "--stop", "--force", "ntfy", quiet=True, check=False)
|
||||
for path in present:
|
||||
if path.is_dir() and not path.is_symlink():
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
path.unlink(missing_ok=True)
|
||||
return present
|
||||
|
||||
|
||||
def server_report(config):
|
||||
@@ -370,7 +414,8 @@ def update(config):
|
||||
"""Brings this installation to the newest source: pull, reinstall the same
|
||||
way it was installed (data and credentials kept), restart, report."""
|
||||
source = Path(config.get("source") or "")
|
||||
if not (source / "install.sh").is_file():
|
||||
# No recorded source must not fall back to the current directory.
|
||||
if not config.get("source") or not (source / "install.sh").is_file():
|
||||
raise ValueError("This installation does not record its source checkout; "
|
||||
"run ./install from your Pipelines checkout to update it")
|
||||
if healthy(f"http://127.0.0.1:{config['server_port']}/healthz"):
|
||||
@@ -408,13 +453,12 @@ def supervise(config):
|
||||
pidfile.write_text(str(os.getpid()))
|
||||
stopped = False
|
||||
child = None
|
||||
ntfy_child = None
|
||||
web_child = None
|
||||
|
||||
def stopping(*_):
|
||||
nonlocal stopped
|
||||
stopped = True
|
||||
for process in (child, ntfy_child, web_child):
|
||||
for process in (child, web_child):
|
||||
if process is not None and process.poll() is None:
|
||||
process.terminate()
|
||||
|
||||
@@ -422,20 +466,13 @@ def supervise(config):
|
||||
signal.signal(signal.SIGINT, stopping)
|
||||
try:
|
||||
require_web_app(config)
|
||||
if ntfy_mode(config) == "native":
|
||||
ntfy_child = ntfy_start(config)
|
||||
else:
|
||||
compose(config, "up", "-d", "ntfy", quiet=True)
|
||||
wait_health(ntfy_health_url(config))
|
||||
# An ntfy an older supervisor left running is stopped, not reused.
|
||||
stop_legacy_ntfy(config)
|
||||
if stopped:
|
||||
return
|
||||
env = dict(os.environ)
|
||||
env = {key: value for key, value in os.environ.items() if not key.startswith("PIPELINES_NTFY_")}
|
||||
env.update(config.get("opencode_env", {}))
|
||||
env.update(HOME=str(Path.home()), PATH=config["path"], TZ=config["timezone"],
|
||||
PIPELINES_NTFY_URL=f"http://127.0.0.1:{config['ntfy_port']}/{config['topic']}",
|
||||
PIPELINES_NTFY_PUBLIC_URL=config["public_url"],
|
||||
PIPELINES_NTFY_TOKEN_FILE=str(root / "secrets/publisher-token"))
|
||||
env.pop("PIPELINES_NTFY_TOKEN", None)
|
||||
env.update(HOME=str(Path.home()), PATH=config["path"], TZ=config["timezone"])
|
||||
# The server requires, and the proxy and every child CLI send, the
|
||||
# shared token in this file (installs from before it have none).
|
||||
env.update(server_token_env(config))
|
||||
@@ -483,17 +520,6 @@ def supervise(config):
|
||||
except subprocess.TimeoutExpired:
|
||||
child.kill()
|
||||
child.wait()
|
||||
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)
|
||||
|
||||
|
||||
@@ -501,15 +527,17 @@ def uninstall(config, purge=False, yes=False):
|
||||
root = Path(config["prefix"])
|
||||
if not yes and input("Uninstall Pipelines? [y/N] ").strip().lower() != "y":
|
||||
return
|
||||
if purge and not yes and input("Also DELETE pipeline history, credentials, and this install's ntfy volume? Type DELETE: ") != "DELETE":
|
||||
if purge and not yes and input("Also DELETE pipeline history and credentials? Type DELETE: ") != "DELETE":
|
||||
raise ValueError("Purge canceled; nothing deleted")
|
||||
stop(config)
|
||||
if registration(config):
|
||||
if platform.system() != "Darwin":
|
||||
run(["systemctl", "--user", "disable", config["label"] + ".service"], quiet=True, check=False)
|
||||
Path(registration(config)).unlink(missing_ok=True)
|
||||
if ntfy_mode(config) != "native":
|
||||
compose(config, "down", *(["--volumes"] if purge else []), quiet=True)
|
||||
# Anything an older install left for ntfy goes too, manifest or not.
|
||||
retire_ntfy(config)
|
||||
if install_mode(config) != "native" and (root / "compose.yaml").is_file():
|
||||
compose(config, "down", "--remove-orphans", *(["--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):
|
||||
@@ -519,7 +547,7 @@ def uninstall(config, purge=False, yes=False):
|
||||
if purge:
|
||||
# Only the explicitly identified, owned installation directory is removed.
|
||||
shutil.rmtree(root)
|
||||
print("Removed installation and its pipeline/ntfy data. Host OpenCode was untouched.")
|
||||
print("Removed installation and its pipeline data. Host OpenCode was untouched.")
|
||||
else:
|
||||
for path in (root / "bin", root / "lib"):
|
||||
if path.exists():
|
||||
@@ -527,7 +555,7 @@ def uninstall(config, purge=False, yes=False):
|
||||
config["registration"] = None
|
||||
config["uninstalled"] = True
|
||||
(root / MARKER).write_text(json.dumps(config, indent=2))
|
||||
print(f"Uninstalled. Data and ntfy volume retained at {root}; reinstall to reuse them.")
|
||||
print(f"Uninstalled. Data retained at {root}; reinstall to reuse it.")
|
||||
|
||||
|
||||
def main():
|
||||
@@ -569,8 +597,6 @@ def main():
|
||||
elif args.action in ("status", "doctor"):
|
||||
report(config)
|
||||
print("Pipeline server:", "healthy" if healthy(f"http://127.0.0.1:{config['server_port']}/healthz") 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)
|
||||
print("Host OpenCode API: responding (model execution is a separate check)")
|
||||
|
||||
Reference in New Issue
Block a user