Link <name>-update into /usr/bin so pct exec finds it without the full path

pct exec runs without a login shell and its PATH may lack /usr/local/bin.
setup.sh adds the link on Linux; update.sh adds it to older installs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-04 21:05:20 -08:00
parent be727949c1
commit c9738358de
8 changed files with 19 additions and 11 deletions

View file

@ -31,7 +31,7 @@ Remote: `https://git.neilbantoc.dev/services/network-monitor.git` (Gitea). The r
| Mode | How it runs | Update command | Logs | | Mode | How it runs | Update command | Logs |
|---|---|---|---| |---|---|---|---|
| lxc (Proxmox node) | A container made by the installer; inside it, the same as native Linux. | `pct exec <ctid> -- /usr/local/bin/<name>-update` (full path: `pct exec` runs with a minimal PATH without `/usr/local/bin`) | `pct exec <ctid> -- journalctl -u <name> -f` | | lxc (Proxmox node) | A container made by the installer; inside it, the same as native Linux. | `pct exec <ctid> -- <name>-update` (the command is in `/usr/local/bin`, linked into `/usr/bin` on Linux because `pct exec`'s PATH may lack `/usr/local/bin`; `update.sh` adds the link to older installs) | `pct exec <ctid> -- journalctl -u <name> -f` |
| docker | `compose.yml` (hub, bridge, port 8000) / `compose.probe.yml` (probe, `network_mode: host`). The image is runtime only; the source is cloned into a volume. | `docker exec network-monitor update` / `docker exec network-probe update` | `docker logs -f <name>` | | docker | `compose.yml` (hub, bridge, port 8000) / `compose.probe.yml` (probe, `network_mode: host`). The image is runtime only; the source is cloned into a volume. | `docker exec network-monitor update` / `docker exec network-probe update` | `docker logs -f <name>` |
| native, Linux | `/opt/<name>` is the git checkout plus `.venv/`, `data/`, `.env`, `.native`. A systemd unit `<name>.service` runs `native/run.sh` as user `netmon`. | `sudo <name>-update` | `journalctl -u <name> -f` | | native, Linux | `/opt/<name>` is the git checkout plus `.venv/`, `data/`, `.env`, `.native`. A systemd unit `<name>.service` runs `native/run.sh` as user `netmon`. | `sudo <name>-update` | `journalctl -u <name> -f` |
| native, macOS | Same layout, owned by the installing user. The LaunchDaemon `/Library/LaunchDaemons/dev.neilbantoc.<name>.plist` runs the app as **root**: macOS 15 Local Network privacy blocks LAN connections from a daemon running as a user (`[Errno 65] No route to host` while curl works), and root daemons are exempt (tested on 15.3.1). | `<name>-update` (no sudo; it calls sudo for `launchctl kickstart`) | `/opt/<name>/data/service.log` | | native, macOS | Same layout, owned by the installing user. The LaunchDaemon `/Library/LaunchDaemons/dev.neilbantoc.<name>.plist` runs the app as **root**: macOS 15 Local Network privacy blocks LAN connections from a daemon running as a user (`[Errno 65] No route to host` while curl works), and root daemons are exempt (tested on 15.3.1). | `<name>-update` (no sudo; it calls sudo for `launchctl kickstart`) | `/opt/<name>/data/service.log` |
@ -43,7 +43,7 @@ Remote: `https://git.neilbantoc.dev/services/network-monitor.git` (Gitea). The r
The mode is stored as `INSTALL_MODE` in `/opt/<name>/.env`. The mode is stored as `INSTALL_MODE` in `/opt/<name>/.env`.
The intended topology: The intended topology:
- **Proxmox VE nodes:** `lxc` mode, the default when `pct` and `/etc/pve` exist. Running the installer on the node as root creates (or reuses, found by tag `netmon-hub` / `netmon-probe`) an unprivileged Debian LXC on `vmbr0`. It then `pct push`es itself into the container (re-assembled from its own functions with `declare -f`) and runs there in native mode. `LXC_*` variables override ID, storage, bridge, IP and size. Day to day: `pct exec <ctid> -- /usr/local/bin/network-probe-update`, or `pct enter <ctid>` and run it there. - **Proxmox VE nodes:** `lxc` mode, the default when `pct` and `/etc/pve` exist. Running the installer on the node as root creates (or reuses, found by tag `netmon-hub` / `netmon-probe`) an unprivileged Debian LXC on `vmbr0`. It then `pct push`es itself into the container (re-assembled from its own functions with `declare -f`) and runs there in native mode. `LXC_*` variables override ID, storage, bridge, IP and size. Day to day: `pct exec <ctid> -- network-probe-update`, or `pct enter <ctid>` and run it there.
- **Names and port:** in an LXC (lxc mode, or native mode where `systemd-detect-virt -c` says lxc), `native/setup.sh` installs avahi-daemon, which announces `<hostname>.local`. It comments out `rlimit-nproc` in `avahi-daemon.conf`, because the stock value stops avahi-daemon from starting in unprivileged containers. The hub defaults to `HOST_PORT=80` there, granted by `AmbientCapabilities=CAP_NET_BIND_SERVICE`, unless `HOST_PORT` is passed. - **Names and port:** in an LXC (lxc mode, or native mode where `systemd-detect-virt -c` says lxc), `native/setup.sh` installs avahi-daemon, which announces `<hostname>.local`. It comments out `rlimit-nproc` in `avahi-daemon.conf`, because the stock value stops avahi-daemon from starting in unprivileged containers. The hub defaults to `HOST_PORT=80` there, granted by `AmbientCapabilities=CAP_NET_BIND_SERVICE`, unless `HOST_PORT` is passed.
- **Inner run:** lxc mode runs the inner installer with `LANG/LC_ALL=C.UTF-8` (the node's locale may not exist in the container) and `NETMON_NESTED=1`, which shortens the inner summary. - **Inner run:** lxc mode runs the inner installer with `LANG/LC_ALL=C.UTF-8` (the node's locale may not exist in the container) and `NETMON_NESTED=1`, which shortens the inner summary.
- **Probe commands:** Linux probes usually can't resolve `.local`. When the UI is opened by a `.local` name, the Add probe command uses `hub_lan_url` (the hub's own IP, native installs only) as `HUB_URL`. - **Probe commands:** Linux probes usually can't resolve `.local`. When the UI is opened by a `.local` name, the Add probe command uses `hub_lan_url` (the hub's own IP, native installs only) as `HUB_URL`.

View file

@ -108,7 +108,7 @@ Run the same commands as above on the node, as root. The installer:
- named `netmon-hub` or `netmon-probe-<node>` - named `netmon-hub` or `netmon-probe-<node>`
2. **Starts it** and waits for network. 2. **Starts it** and waits for network.
3. **Copies the installer in** and runs it in native mode. It installs Python, sets up ping and creates the systemd service. 3. **Copies the installer in** and runs it in native mode. It installs Python, sets up ping and creates the systemd service.
4. **Prints the container's IP** and the `pct exec` commands to update it, read its logs and edit its settings. `pct exec` runs commands with a minimal PATH that doesn't include `/usr/local/bin`, so the update command needs its full path: `pct exec <ctid> -- /usr/local/bin/network-monitor-update`. Inside the container (`pct enter <ctid>`), plain `network-monitor-update` works. 4. **Prints the container's IP** and the `pct exec` commands to update it, read its logs and edit its settings. The update command is in `/usr/local/bin` and linked into `/usr/bin`, so `pct exec <ctid> -- network-monitor-update` finds it even though `pct exec` doesn't run a login shell. Inside the container (`pct enter <ctid>`), the same command works.
To change the defaults, set these before `bash`: To change the defaults, set these before `bash`:
@ -172,7 +172,7 @@ read -rsp 'Gitea token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Author
git push # from your machine git push # from your machine
docker exec network-monitor update # hub, Docker docker exec network-monitor update # hub, Docker
sudo network-monitor-update # hub, native Linux (no sudo as root; macOS: network-monitor-update) sudo network-monitor-update # hub, native Linux (no sudo as root; macOS: network-monitor-update)
pct exec <ctid> -- /usr/local/bin/network-monitor-update # hub in a Proxmox LXC, from the node pct exec <ctid> -- network-monitor-update # hub in a Proxmox LXC, from the node
docker exec network-probe update # probe, Docker docker exec network-probe update # probe, Docker
sudo network-probe-update # probe, native Linux (macOS: network-probe-update) sudo network-probe-update # probe, native Linux (macOS: network-probe-update)
``` ```
@ -197,7 +197,7 @@ The installer prints the uninstall command at the end. In short:
| Install | Command | | Install | Command |
|---|---| |---|---|
| Docker | `cd /opt/<name> && docker compose -f <compose.yml or compose.probe.yml> down -v`, then `rm -rf /opt/<name>` | | Docker | `cd /opt/<name> && docker compose -f <compose.yml or compose.probe.yml> down -v`, then `rm -rf /opt/<name>` |
| Native Linux | `systemctl disable --now <name> && rm -rf /opt/<name> /etc/systemd/system/<name>.service /usr/local/bin/<name>-update` | | Native Linux | `systemctl disable --now <name> && rm -rf /opt/<name> /etc/systemd/system/<name>.service /usr/local/bin/<name>-update /usr/bin/<name>-update` |
| macOS | `sudo launchctl bootout system/dev.neilbantoc.<name>; sudo rm -rf /opt/<name> /Library/LaunchDaemons/dev.neilbantoc.<name>.plist /usr/local/bin/<name>-update` | | macOS | `sudo launchctl bootout system/dev.neilbantoc.<name>; sudo rm -rf /opt/<name> /Library/LaunchDaemons/dev.neilbantoc.<name>.plist /usr/local/bin/<name>-update` |
`<name>` is `network-monitor` (hub) or `network-probe`. `<name>` is `network-monitor` (hub) or `network-probe`.

View file

@ -225,7 +225,7 @@ lxc_install() {
echo " open the web UI: http://$host.local$suffix (or http://${ip:-<container-ip>}$suffix)" echo " open the web UI: http://$host.local$suffix (or http://${ip:-<container-ip>}$suffix)"
fi fi
echo " give it a fixed IP: a DHCP reservation, or pct set $CTID --net0 name=eth0,bridge=...,ip=<ip>/<cidr>,gw=<gw>" echo " give it a fixed IP: a DHCP reservation, or pct set $CTID --net0 name=eth0,bridge=...,ip=<ip>/<cidr>,gw=<gw>"
echo " deploy a new commit: pct exec $CTID -- /usr/local/bin/$NAME-update" echo " deploy a new commit: pct exec $CTID -- $NAME-update"
echo " logs: pct exec $CTID -- journalctl -u $NAME -f" echo " logs: pct exec $CTID -- journalctl -u $NAME -f"
echo " settings: pct exec $CTID -- nano /opt/$NAME/.env (then: pct exec $CTID -- systemctl restart $NAME)" echo " settings: pct exec $CTID -- nano /opt/$NAME/.env (then: pct exec $CTID -- systemctl restart $NAME)"
echo " shell inside: pct enter $CTID" echo " shell inside: pct enter $CTID"
@ -517,7 +517,7 @@ finish_message() {
# Root (e.g. inside an LXC, which usually has no sudo) runs it directly. # Root (e.g. inside an LXC, which usually has no sudo) runs it directly.
deploy="$NAME-update"; [ "$(id -u)" = 0 ] || deploy="sudo $deploy" deploy="$NAME-update"; [ "$(id -u)" = 0 ] || deploy="sudo $deploy"
logs="journalctl -u $NAME -f" logs="journalctl -u $NAME -f"
remove="sudo systemctl disable --now $NAME && sudo rm -rf $INSTALL_DIR /etc/systemd/system/$NAME.service /usr/local/bin/$NAME-update" remove="sudo systemctl disable --now $NAME && sudo rm -rf $INSTALL_DIR /etc/systemd/system/$NAME.service /usr/local/bin/$NAME-update /usr/bin/$NAME-update"
else else
deploy="$NAME-update"; logs="tail -f $INSTALL_DIR/data/service.log" deploy="$NAME-update"; logs="tail -f $INSTALL_DIR/data/service.log"
remove="sudo launchctl bootout system/dev.neilbantoc.$NAME; sudo rm -rf $INSTALL_DIR /Library/LaunchDaemons/dev.neilbantoc.$NAME.plist /usr/local/bin/$NAME-update" remove="sudo launchctl bootout system/dev.neilbantoc.$NAME; sudo rm -rf $INSTALL_DIR /Library/LaunchDaemons/dev.neilbantoc.$NAME.plist /usr/local/bin/$NAME-update"

View file

@ -220,7 +220,7 @@ lxc_install() {
echo " open the web UI: http://$host.local$suffix (or http://${ip:-<container-ip>}$suffix)" echo " open the web UI: http://$host.local$suffix (or http://${ip:-<container-ip>}$suffix)"
fi fi
echo " give it a fixed IP: a DHCP reservation, or pct set $CTID --net0 name=eth0,bridge=...,ip=<ip>/<cidr>,gw=<gw>" echo " give it a fixed IP: a DHCP reservation, or pct set $CTID --net0 name=eth0,bridge=...,ip=<ip>/<cidr>,gw=<gw>"
echo " deploy a new commit: pct exec $CTID -- /usr/local/bin/$NAME-update" echo " deploy a new commit: pct exec $CTID -- $NAME-update"
echo " logs: pct exec $CTID -- journalctl -u $NAME -f" echo " logs: pct exec $CTID -- journalctl -u $NAME -f"
echo " settings: pct exec $CTID -- nano /opt/$NAME/.env (then: pct exec $CTID -- systemctl restart $NAME)" echo " settings: pct exec $CTID -- nano /opt/$NAME/.env (then: pct exec $CTID -- systemctl restart $NAME)"
echo " shell inside: pct enter $CTID" echo " shell inside: pct enter $CTID"
@ -512,7 +512,7 @@ finish_message() {
# Root (e.g. inside an LXC, which usually has no sudo) runs it directly. # Root (e.g. inside an LXC, which usually has no sudo) runs it directly.
deploy="$NAME-update"; [ "$(id -u)" = 0 ] || deploy="sudo $deploy" deploy="$NAME-update"; [ "$(id -u)" = 0 ] || deploy="sudo $deploy"
logs="journalctl -u $NAME -f" logs="journalctl -u $NAME -f"
remove="sudo systemctl disable --now $NAME && sudo rm -rf $INSTALL_DIR /etc/systemd/system/$NAME.service /usr/local/bin/$NAME-update" remove="sudo systemctl disable --now $NAME && sudo rm -rf $INSTALL_DIR /etc/systemd/system/$NAME.service /usr/local/bin/$NAME-update /usr/bin/$NAME-update"
else else
deploy="$NAME-update"; logs="tail -f $INSTALL_DIR/data/service.log" deploy="$NAME-update"; logs="tail -f $INSTALL_DIR/data/service.log"
remove="sudo launchctl bootout system/dev.neilbantoc.$NAME; sudo rm -rf $INSTALL_DIR /Library/LaunchDaemons/dev.neilbantoc.$NAME.plist /usr/local/bin/$NAME-update" remove="sudo launchctl bootout system/dev.neilbantoc.$NAME; sudo rm -rf $INSTALL_DIR /Library/LaunchDaemons/dev.neilbantoc.$NAME.plist /usr/local/bin/$NAME-update"

View file

@ -16,7 +16,7 @@ export ROLE APP_VERSION PORT INSTALL_DIR INSTALL_MODE=native DATA_DIR="$INSTALL_
UPDATE_COMMAND="$NAME-update" UPDATE_COMMAND="$NAME-update"
if [ "$PLATFORM" = systemd ] && command -v sudo >/dev/null 2>&1; then UPDATE_COMMAND="sudo $NAME-update"; fi if [ "$PLATFORM" = systemd ] && command -v sudo >/dev/null 2>&1; then UPDATE_COMMAND="sudo $NAME-update"; fi
if systemd-detect-virt -cq 2>/dev/null; then if systemd-detect-virt -cq 2>/dev/null; then
UPDATE_COMMAND="$NAME-update (from the Proxmox node: pct exec <ctid> -- /usr/local/bin/$NAME-update)" UPDATE_COMMAND="$NAME-update (from the Proxmox node: pct exec <ctid> -- $NAME-update)"
fi fi
export UPDATE_COMMAND export UPDATE_COMMAND
exec "$INSTALL_DIR/.venv/bin/uvicorn" app.main:app --host "$(app_host)" --port "$PORT" \ exec "$INSTALL_DIR/.venv/bin/uvicorn" app.main:app --host "$(app_host)" --port "$PORT" \

View file

@ -91,6 +91,11 @@ printf '#!/bin/sh\n# Deploy a new commit of %s (native install). See: %s-update
as_root mkdir -p /usr/local/bin as_root mkdir -p /usr/local/bin
as_root install -m 755 "$tmp" "/usr/local/bin/$NAME-update" as_root install -m 755 "$tmp" "/usr/local/bin/$NAME-update"
rm -f "$tmp" rm -f "$tmp"
if [ "$PLATFORM" = systemd ]; then
# Also in /usr/bin, which is on every PATH: `pct exec <ctid> -- <name>-update` from a Proxmox
# node runs without a login shell and its PATH may not include /usr/local/bin.
as_root ln -sfn "/usr/local/bin/$NAME-update" "/usr/bin/$NAME-update"
fi
native_log "service" native_log "service"
if [ "$PLATFORM" = systemd ]; then if [ "$PLATFORM" = systemd ]; then

View file

@ -26,6 +26,9 @@ while [ $# -gt 0 ]; do
done done
if [ "$PLATFORM" = systemd ] && [ "$(id -u)" != 0 ]; then native_die "run it with sudo: sudo $NAME-update $*"; fi if [ "$PLATFORM" = systemd ] && [ "$(id -u)" != 0 ]; then native_die "run it with sudo: sudo $NAME-update $*"; fi
if [ "$PLATFORM" = systemd ] && [ ! -e "/usr/bin/$NAME-update" ]; then # installs older than the /usr/bin link
ln -sfn "/usr/local/bin/$NAME-update" "/usr/bin/$NAME-update" 2>/dev/null || true
fi
if [ "$PLATFORM" = launchd ] && [ "$(id -u)" = 0 ] && [ "$SVC_USER" != root ]; then if [ "$PLATFORM" = launchd ] && [ "$(id -u)" = 0 ] && [ "$SVC_USER" != root ]; then
exec sudo -u "$SVC_USER" NETMON_DIR="$INSTALL_DIR" /bin/bash "$0" "$@" exec sudo -u "$SVC_USER" NETMON_DIR="$INSTALL_DIR" /bin/bash "$0" "$@"
fi fi

View file

@ -102,7 +102,7 @@ export -f pct pvesh pveam pvesm sleep id
for part in ("INSTALL_MODE=native", "HOST_PORT=80", "LC_ALL=C.UTF-8", "LANG=C.UTF-8", "NETMON_NESTED=1"): for part in ("INSTALL_MODE=native", "HOST_PORT=80", "LC_ALL=C.UTF-8", "LANG=C.UTF-8", "NETMON_NESTED=1"):
assert part in inner, part assert part in inner, part
assert "http://netmon-hub.local (or http://192.168.68.50)" in r.stdout assert "http://netmon-hub.local (or http://192.168.68.50)" in r.stdout
assert "pct exec 105 -- /usr/local/bin/network-monitor-update" in r.stdout # pct exec has no /usr/local/bin in PATH assert "pct exec 105 -- network-monitor-update" in r.stdout # works because setup.sh links it into /usr/bin
# The pushed script is a complete installer for the same role. # The pushed script is a complete installer for the same role.
text = pushed.read_text() text = pushed.read_text()
assert "NETMON_ROLE=hub" in text and text.rstrip().endswith('main "$@"') assert "NETMON_ROLE=hub" in text and text.rstrip().endswith('main "$@"')