Files
LangBot/packaging/fnos/cmd/upgrade_init
T
“sheetung” 34f1e3d56f feat(fnos): run entirely without root and harden process lifecycle
- Switch privilege model to run-as: package (zero root, per fnOS guide)
- Borrow App Store python312 instead of bundling CPython; keep bundled uv
- Move venv, HOME and caches onto the persistent data share
- Start service via setsid; stop/upgrade kill the whole process group
- Sweep stray runtime/box orphans in install/upgrade init hooks
- Track LangBot 4.10.11 (manifest baseline + upstream merge)
2026-09-18 16:20:32 +08:00

37 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
# cmd/upgrade_init - pre-upgrade hook (runs before files are replaced)
# 1. Stop the running LangBot instance — whole process group, so stdio
# children (plugin runtime, Box) die with the parent.
# 2. Sweep stray processes from a previous crash/upgrade: orphans whose
# parent was hard-killed keep running and hold the runtime/box ws ports,
# which breaks the next start.
PID_FILE="${TRIM_PKGVAR}/langbot.pid"
if [ -f "${PID_FILE}" ]; then
PID=$(cat "${PID_FILE}" | tr -d '[:space:]')
if [ -n "${PID}" ] && kill -0 "${PID}" 2>/dev/null; then
# Instances started with setsid have PID == PGID; the plain-PID kill
# covers instances started before that change.
kill -TERM -- "-${PID}" 2>/dev/null
kill -TERM "${PID}" 2>/dev/null
for _ in 1 2 3 4 5 6 7 8 9 10; do
kill -0 "${PID}" 2>/dev/null || break
sleep 1
done
kill -KILL -- "-${PID}" 2>/dev/null
kill -KILL "${PID}" 2>/dev/null
fi
rm -f "${PID_FILE}"
fi
# Stray sweep: match only our volume paths (venv/uv under the app dir on
# @appcenter, venv/HOME/caches under the data share on @appshare). This
# script itself runs from /var/apps/<appname>/cmd/, so it never matches
# itself. No match is the normal case on a clean upgrade — pkill exits 1.
RUN_USER=$(id -un)
pkill -KILL -u "${RUN_USER}" -f "appcenter/langbot" 2>/dev/null || true
pkill -KILL -u "${RUN_USER}" -f "appshare/langbot" 2>/dev/null || true
exit 0