diff --git a/CLAUDE.md b/CLAUDE.md index 1ac43d3..ef05d6d 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -26,7 +26,7 @@ Remote: `https://git.neilbantoc.dev/services/network-monitor.git` (Gitea). The r | 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 -- -update` | `pct exec -- journalctl -u -f` | +| lxc (Proxmox node) | A container made by the installer; inside it, the same as native Linux. | `pct exec -- /usr/local/bin/-update` (full path: `pct exec` runs with a minimal PATH without `/usr/local/bin`) | `pct exec -- journalctl -u -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 ` | | native, Linux | `/opt/` is the git checkout plus `.venv/`, `data/`, `.env`, `.native`. A systemd unit `.service` runs `native/run.sh` as user `netmon`. | `sudo -update` | `journalctl -u -f` | | native, macOS | Same layout. The LaunchDaemon `/Library/LaunchDaemons/dev.neilbantoc..plist` runs as the installing user. | `-update` (no sudo; it calls sudo for `launchctl kickstart`) | `/opt//data/service.log` | @@ -38,7 +38,7 @@ Remote: `https://git.neilbantoc.dev/services/network-monitor.git` (Gitea). The r The mode is stored as `INSTALL_MODE` in `/opt//.env`. 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 -- network-probe-update`, `pct enter `. +- **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 -- /usr/local/bin/network-probe-update`, or `pct enter ` 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 `.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. - **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`. diff --git a/README.md b/README.md index ceba886..45ef46d 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ Run the same commands as above on the node, as root. The installer: - named `netmon-hub` or `netmon-probe-` 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. -4. **Prints the container's IP** and the `pct exec` commands to update it, read its logs and edit its settings. +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 -- /usr/local/bin/network-monitor-update`. Inside the container (`pct enter `), plain `network-monitor-update` works. To change the defaults, set these before `bash`: @@ -169,7 +169,8 @@ read -rsp 'Gitea token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Author ```bash git push # from your machine docker exec network-monitor update # hub, Docker -sudo network-monitor-update # hub, native Linux (macOS: network-monitor-update) +sudo network-monitor-update # hub, native Linux (no sudo as root; macOS: network-monitor-update) +pct exec -- /usr/local/bin/network-monitor-update # hub in a Proxmox LXC, from the node docker exec network-probe update # probe, Docker sudo network-probe-update # probe, native Linux (macOS: network-probe-update) ``` diff --git a/install-probe.sh b/install-probe.sh index 05b20d6..641df48 100755 --- a/install-probe.sh +++ b/install-probe.sh @@ -225,7 +225,7 @@ lxc_install() { echo " open the web UI: http://$host.local$suffix (or http://${ip:-}$suffix)" fi echo " give it a fixed IP: a DHCP reservation, or pct set $CTID --net0 name=eth0,bridge=...,ip=/,gw=" - echo " deploy a new commit: pct exec $CTID -- $NAME-update" + echo " deploy a new commit: pct exec $CTID -- /usr/local/bin/$NAME-update" 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 " shell inside: pct enter $CTID" @@ -514,7 +514,9 @@ finish_message() { deploy="docker exec $NAME update"; logs="docker logs -f $NAME" remove="cd $INSTALL_DIR && docker compose -f $COMPOSE_FILE down -v" elif [ "$OS" = Linux ]; then - deploy="sudo $NAME-update"; logs="journalctl -u $NAME -f" + # Root (e.g. inside an LXC, which usually has no sudo) runs it directly. + deploy="$NAME-update"; [ "$(id -u)" = 0 ] || deploy="sudo $deploy" + 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" else deploy="$NAME-update"; logs="tail -f $INSTALL_DIR/data/service.log" diff --git a/install.sh b/install.sh index 1aad39e..2c44c9e 100755 --- a/install.sh +++ b/install.sh @@ -220,7 +220,7 @@ lxc_install() { echo " open the web UI: http://$host.local$suffix (or http://${ip:-}$suffix)" fi echo " give it a fixed IP: a DHCP reservation, or pct set $CTID --net0 name=eth0,bridge=...,ip=/,gw=" - echo " deploy a new commit: pct exec $CTID -- $NAME-update" + echo " deploy a new commit: pct exec $CTID -- /usr/local/bin/$NAME-update" 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 " shell inside: pct enter $CTID" @@ -509,7 +509,9 @@ finish_message() { deploy="docker exec $NAME update"; logs="docker logs -f $NAME" remove="cd $INSTALL_DIR && docker compose -f $COMPOSE_FILE down -v" elif [ "$OS" = Linux ]; then - deploy="sudo $NAME-update"; logs="journalctl -u $NAME -f" + # Root (e.g. inside an LXC, which usually has no sudo) runs it directly. + deploy="$NAME-update"; [ "$(id -u)" = 0 ] || deploy="sudo $deploy" + 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" else deploy="$NAME-update"; logs="tail -f $INSTALL_DIR/data/service.log" diff --git a/native/run.sh b/native/run.sh index 60b2d9d..8a4b496 100755 --- a/native/run.sh +++ b/native/run.sh @@ -11,7 +11,13 @@ unset GIT_TOKEN GIT_USERNAME GIT_SSH_KEY APP_VERSION=$(git -c safe.directory="$INSTALL_DIR" -C "$INSTALL_DIR" rev-parse --short HEAD 2>/dev/null || echo dev) PORT=$(app_port) export ROLE APP_VERSION PORT INSTALL_DIR INSTALL_MODE=native DATA_DIR="$INSTALL_DIR/data" PYTHONUNBUFFERED=1 PYTHONDONTWRITEBYTECODE=1 -export UPDATE_COMMAND="sudo $NAME-update" -[ "$PLATFORM" = launchd ] && UPDATE_COMMAND="$NAME-update" +# How to deploy, as shown on the Settings page. sudo only where it exists (LXCs usually have +# none and you are root there); macOS runs it as the installing user. +UPDATE_COMMAND="$NAME-update" +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 + UPDATE_COMMAND="$NAME-update (from the Proxmox node: pct exec -- /usr/local/bin/$NAME-update)" +fi +export UPDATE_COMMAND exec "$INSTALL_DIR/.venv/bin/uvicorn" app.main:app --host "$(app_host)" --port "$PORT" \ --no-server-header --timeout-graceful-shutdown 10 diff --git a/tests/test_installers.py b/tests/test_installers.py index 70f06b4..98e49fb 100644 --- a/tests/test_installers.py +++ b/tests/test_installers.py @@ -102,6 +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"): assert part in inner, part 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 # The pushed script is a complete installer for the same role. text = pushed.read_text() assert "NETMON_ROLE=hub" in text and text.rstrip().endswith('main "$@"')