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:
parent
a96ae4e825
commit
cd2deda996
9 changed files with 136 additions and 17 deletions
|
|
@ -70,12 +70,19 @@ main() {
|
|||
fi
|
||||
|
||||
CALLER_MODE=${INSTALL_MODE:-}
|
||||
CALLER_PORT=${!PORT_KEY:-}
|
||||
step "source"
|
||||
load_existing_env
|
||||
REPO_URL=${REPO_URL:-$DEFAULT_REPO_URL}
|
||||
REPO_REF=${REPO_REF:-$DEFAULT_REF}
|
||||
printf -v "$PORT_KEY" '%s' "${!PORT_KEY:-$DEFAULT_PORT}"
|
||||
choose_mode
|
||||
# In an LXC the hub is the only service on its "machine": serve it on port 80 so
|
||||
# http://<container-hostname>.local works without a port (Avahi announces the name).
|
||||
if [ "$ROLE" = hub ] && [ -z "$CALLER_PORT" ] && uses_lan_name; then
|
||||
HOST_PORT=80
|
||||
in_list HOST_PORT "$PASSED" || PASSED="${PASSED}HOST_PORT "
|
||||
fi
|
||||
if [ "$MODE" = lxc ]; then lxc_install; return; fi
|
||||
|
||||
step "prerequisites"
|
||||
|
|
@ -96,7 +103,9 @@ main() {
|
|||
if [ "$MODE" = docker ]; then
|
||||
(cd "$INSTALL_DIR" && $DOCKER compose -f "$COMPOSE_FILE" up -d --build --remove-orphans)
|
||||
else
|
||||
NAME=$NAME ROLE=$ROLE INSTALL_DIR=$INSTALL_DIR bash "$INSTALL_DIR/native/setup.sh"
|
||||
AVAHI=0
|
||||
if uses_lan_name; then AVAHI=1; fi
|
||||
NAME=$NAME ROLE=$ROLE INSTALL_DIR=$INSTALL_DIR AVAHI=$AVAHI bash "$INSTALL_DIR/native/setup.sh"
|
||||
fi
|
||||
wait_healthy
|
||||
|
||||
|
|
@ -119,6 +128,13 @@ is_lxc() {
|
|||
grep -qa 'container=lxc' /proc/1/environ 2>/dev/null
|
||||
}
|
||||
|
||||
# One service per (virtual) machine: an LXC, or the container lxc mode creates. There the
|
||||
# install announces <hostname>.local with Avahi, and the hub takes port 80.
|
||||
uses_lan_name() {
|
||||
[ "${NETMON_LAN_NAME:-}" = 1 ] && return 0
|
||||
[ "$MODE" = lxc ] || { [ "$MODE" = native ] && is_lxc; }
|
||||
}
|
||||
|
||||
is_pve_host() {
|
||||
[ "$OS" = Linux ] && command -v pct >/dev/null 2>&1 && [ -d "${NETMON_PVE_DIR:-/etc/pve}" ]
|
||||
}
|
||||
|
|
@ -191,7 +207,8 @@ lxc_install() {
|
|||
{ printf '#!/usr/bin/env bash\nNETMON_ROLE=%s\n' "$ROLE"; declare -f; printf 'main "$@"\n'; } > "$script"
|
||||
pct push "$CTID" "$script" /root/netmon-install.sh --perms 0700
|
||||
rm -f "$script"
|
||||
set -- env INSTALL_MODE=native
|
||||
# C.UTF-8 exists in every Debian container; the node's own LANG may not.
|
||||
set -- env LANG=C.UTF-8 LC_ALL=C.UTF-8 NETMON_NESTED=1 INSTALL_MODE=native
|
||||
for k in $KEYS; do
|
||||
if [ "$k" != INSTALL_MODE ] && [ -n "${!k:-}" ]; then set -- "$@" "$k=${!k}"; fi
|
||||
done
|
||||
|
|
@ -199,9 +216,14 @@ lxc_install() {
|
|||
pct exec "$CTID" -- rm -f /root/netmon-install.sh
|
||||
|
||||
ip=$(pct exec "$CTID" -- hostname -I 2>/dev/null | cut -d' ' -f1)
|
||||
local host suffix=
|
||||
host=$(pct config "$CTID" | sed -n 's/^hostname: //p')
|
||||
[ "$port" = 80 ] || suffix=":$port"
|
||||
step "done"
|
||||
echo "$NAME runs in Proxmox container $CTID ($(pct config "$CTID" | sed -n 's/^hostname: //p')), IP ${ip:-unknown}."
|
||||
if [ "$ROLE" = hub ]; then echo " open the web UI: http://${ip:-<container-ip>}:$port"; fi
|
||||
echo "$NAME runs in Proxmox container $CTID ($host), IP ${ip:-unknown}."
|
||||
if [ "$ROLE" = hub ]; then
|
||||
echo " open the web UI: http://$host.local$suffix (or http://${ip:-<container-ip>}$suffix)"
|
||||
fi
|
||||
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 -- $NAME-update"
|
||||
echo " logs: pct exec $CTID -- journalctl -u $NAME -f"
|
||||
|
|
@ -486,6 +508,8 @@ my_ip() {
|
|||
|
||||
finish_message() {
|
||||
local port=${!PORT_KEY} deploy logs remove
|
||||
# Run inside a container by lxc mode: the outer installer prints the summary.
|
||||
if [ -n "${NETMON_NESTED:-}" ]; then echo "$NAME ($MODE) is running at $(health_version) on port $port."; return; fi
|
||||
if [ "$MODE" = docker ]; then
|
||||
deploy="docker exec $NAME update"; logs="docker logs -f $NAME"
|
||||
remove="cd $INSTALL_DIR && docker compose -f $COMPOSE_FILE down -v"
|
||||
|
|
@ -498,7 +522,8 @@ finish_message() {
|
|||
fi
|
||||
if [ "$ROLE" = hub ]; then
|
||||
echo "$NAME ($MODE) is running at $(health_version) on port $port."
|
||||
echo " open the web UI: http://$(my_ip):$port"
|
||||
if [ "$port" = 80 ]; then echo " open the web UI: http://$(my_ip)"; else echo " open the web UI: http://$(my_ip):$port"; fi
|
||||
if uses_lan_name; then echo " http://$(hostname -s).local$([ "$port" = 80 ] || echo ":$port")"; fi
|
||||
echo " add probes from: the Probes page; each one shows its install command"
|
||||
else
|
||||
if [ -n "${HUB_URL:-}" ]; then echo "$NAME ($MODE) is running at $(health_version), reporting to $HUB_URL."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue