LXC installs: announce <hostname>.local with Avahi, hub on port 80

In an LXC (lxc mode on a Proxmox node, or native mode inside an LXC), the
installer now:
- installs avahi-daemon (with the rlimit-nproc fix for unprivileged
  containers), so the container answers at <hostname>.local, and lists the
  web UI as a _http._tcp service
- serves the hub on port 80 (CAP_NET_BIND_SERVICE for the netmon user) unless
  HOST_PORT is given, so http://netmon-hub.local works without a port
- runs the inner install with LANG/LC_ALL=C.UTF-8 (no locale warnings from
  the node's LANG) and prints one summary, with the .local address

When the UI is opened by a .local name, the Add probe command uses the hub's
own IP for HUB_URL, since Linux probes usually can't resolve .local.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
neil 2026-11-04 19:19:47 -08:00
parent a96ae4e825
commit cd2deda996
9 changed files with 136 additions and 17 deletions

View file

@ -3,8 +3,10 @@
# and write .env. Idempotent. Linux: run as root, needs systemd. macOS: run as the user
# who will own the install (uses sudo for the launchd daemon and the update command).
# NAME=network-probe ROLE=probe INSTALL_DIR=/opt/network-probe bash native/setup.sh
# AVAHI=1 also announce <hostname>.local with Avahi (Linux; set by the installer in LXCs)
set -euo pipefail
: "${NAME:?}" "${ROLE:?}" "${INSTALL_DIR:?}"
AVAHI=${AVAHI:-0}
. "$INSTALL_DIR/native/lib.sh"
SVC_USER_LINUX=netmon
MIN_PY=11
@ -106,6 +108,8 @@ ExecStart=/bin/bash $INSTALL_DIR/native/run.sh
Restart=always
RestartSec=5
NoNewPrivileges=yes
# Lets the hub listen on port 80 in an LXC (http://<hostname>.local) without running as root.
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
@ -141,4 +145,33 @@ PLIST
as_root launchctl bootstrap system "/Library/LaunchDaemons/$SERVICE.plist"
as_root launchctl enable "system/$SERVICE" >/dev/null 2>&1 || true
fi
if [ "$PLATFORM" = systemd ] && [ "$AVAHI" = 1 ]; then
native_log "avahi: announcing $(hostname -s).local"
if ! command -v avahi-daemon >/dev/null 2>&1; then
if command -v apt-get >/dev/null 2>&1; then
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq avahi-daemon >/dev/null
elif command -v dnf >/dev/null 2>&1; then dnf install -y -q avahi
elif command -v apk >/dev/null 2>&1; then apk add -q avahi
fi
fi
if [ -f /etc/avahi/avahi-daemon.conf ]; then
# The stock rlimit-nproc=3 stops avahi-daemon from starting in unprivileged LXC containers.
sed -i 's/^rlimit-nproc=/#rlimit-nproc=/' /etc/avahi/avahi-daemon.conf
port=$(. "$INSTALL_DIR/native/lib.sh"; load_dotenv "$INSTALL_DIR/.env"; ROLE=$ROLE app_port)
mkdir -p /etc/avahi/services
# Also list the web UI in Bonjour/DNS-SD browsers.
cat > "/etc/avahi/services/$NAME.service" <<SVC
<?xml version="1.0" standalone='no'?>
<!DOCTYPE service-group SYSTEM "avahi-service.dtd">
<service-group>
<name replace-wildcards="yes">Network Monitor ($ROLE) on %h</name>
<service><type>_http._tcp</type><port>$port</port></service>
</service-group>
SVC
systemctl enable avahi-daemon >/dev/null 2>&1 || true
systemctl restart avahi-daemon || native_log "warning: avahi-daemon did not start; check: journalctl -u avahi-daemon"
else
native_log "warning: could not install avahi-daemon; <hostname>.local will not be announced"
fi
fi
native_log "setup done ($PLATFORM service $SERVICE, user $SVC_USER)"