Fix reconcile with remote

This commit is contained in:
Alexander
2026-07-01 14:27:43 +02:00
parent 9699da385b
commit 0e50d8a2a6
4 changed files with 177 additions and 85 deletions
+55 -8
View File
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
#!/usr/bin/env -S nix shell nixpkgs#bash --command bash
#
# vm.sh - Incus VM launcher for musicfs-server
#
@@ -30,6 +30,8 @@
# MUSIC_MOUNT where it appears inside the VM (default: /music)
# LISTEN_PORT gRPC port (host:vm forwarded) (default: 50051)
# RUST_LOG tracing filter for the server (default: info)
# READONLY mount music as read-only (0=writable) (default: 1)
# VM_IP static IPv4 for the VM (default: auto-detected from incusbr0, gateway.145)
#
set -euo pipefail
@@ -40,8 +42,15 @@ MUSIC_SOURCE="${MUSIC_SOURCE:-$HOME/Music}"
MUSIC_MOUNT="${MUSIC_MOUNT:-/music}"
LISTEN_PORT="${LISTEN_PORT:-50051}"
RUST_LOG="${RUST_LOG:-info}"
detect_static_ip() {
if [[ -n "${VM_IP:-}" ]]; then echo "$VM_IP"; return; fi
local bridge_cidr
bridge_cidr="$(incus network get incusbr0 ipv4.address 2>/dev/null || true)"
if [[ -z "$bridge_cidr" ]]; then echo ""; return; fi
local gateway="${bridge_cidr%%/*}"
echo "${gateway%.*}.145"
}
# Fixed inside the VM; the bundle's interpreter+rpath point here.
SERVER_DIR="/opt/musicfs"
LOG_DIR="/var/log/musicfs"
BIN_NAME="musicfs-server"
@@ -60,7 +69,12 @@ vm_running() { incus list "$VM_NAME" -f csv -c n,s 2>/dev/null | grep -q "$VM_NA
device_exists() { incus config device show "$VM_NAME" 2>/dev/null | grep -q "^$1:"; }
# incus -c 4 emits "<ip> (<iface>)"; keep only the address.
vm_ip() { incus list "$VM_NAME" -f csv -c 4 2>/dev/null | head -1 | awk '{print $1}'; }
vm_ip() {
local ip
ip="$(incus list "$VM_NAME" -f csv -c 4 2>/dev/null | head -1 | awk '{print $1}')"
if [[ -n "$ip" ]]; then echo "$ip"; return; fi
detect_static_ip
}
# ──────────────────────────── build + bundle ───────────────────────────
# Emits the host path to the prepared bundle dir on stdout.
@@ -120,10 +134,24 @@ create_vm() {
log "creating VM '$VM_NAME' from $IMAGE ..."
incus init "$IMAGE" "$VM_NAME" --vm
local static_ip
static_ip="$(detect_static_ip)"
if [[ -n "$static_ip" ]]; then
log "reserving static IP: $static_ip"
incus config device add "$VM_NAME" eth0 nic \
network=incusbr0 name=eth0 ipv4.address="$static_ip"
fi
if ! device_exists music; then
log "sharing music: $MUSIC_SOURCE -> $MUSIC_MOUNT (readonly, virtiofs)"
local ro_flag="readonly=true"
local mode="read-only"
if [[ "$READONLY" == "0" ]]; then
ro_flag="readonly=false"
mode="read-write"
fi
log "sharing music: $MUSIC_SOURCE -> $MUSIC_MOUNT ($mode, virtiofs)"
incus config device add "$VM_NAME" music disk \
source="$MUSIC_SOURCE" path="$MUSIC_MOUNT" readonly=true
source="$MUSIC_SOURCE" path="$MUSIC_MOUNT" "$ro_flag"
fi
# No proxy: Incus VM proxies need NAT mode + a *static* instance IP (DHCP is
@@ -255,7 +283,15 @@ print_status() {
printf ' ipv4: %s\n' "${ip:-<none>}"
printf ' image: %s\n' "$IMAGE"
printf ' listen: 0.0.0.0:%s (reach via VM bridge IP above)\n' "$LISTEN_PORT"
printf ' music: %s -> %s\n' "$MUSIC_SOURCE" "$MUSIC_MOUNT"
local ro_actual="read-only"
if vm_exists; then
local ro_val
ro_val="$(incus config device get "$VM_NAME" music readonly 2>/dev/null || true)"
[[ "$ro_val" == "false" ]] && ro_actual="read-write"
else
[[ "$READONLY" == "0" ]] && ro_actual="read-write"
fi
printf ' music: %s -> %s (%s)\n' "$MUSIC_SOURCE" "$MUSIC_MOUNT" "$ro_actual"
printf ' server: %s/server\n' "$SERVER_DIR"
if [ -n "$ip" ]; then
printf '\n test: grpcurl -plaintext %s:%s list\n\n' "$ip" "$LISTEN_PORT"
@@ -273,7 +309,18 @@ usage() {
}
main() {
case "${1:-up}" in
local cmd="${1:-up}"
shift || true
while (( $# )); do
case "$1" in
--writable) [[ -z "${READONLY:-}" ]] && READONLY=0 ;;
--readonly) [[ -z "${READONLY:-}" ]] && READONLY=1 ;;
*) die "unknown flag '$1'. Try: $0 --help" ;;
esac
shift
done
READONLY="${READONLY:-1}"
case "$cmd" in
up) cmd_up ;;
redeploy) cmd_redeploy ;;
restart) cmd_restart ;;
@@ -283,7 +330,7 @@ main() {
down) cmd_down ;;
destroy) cmd_destroy ;;
-h|--help|help) usage ;;
*) die "unknown command '$1'. Try: $0 --help" ;;
*) die "unknown command '$cmd'. Try: $0 --help" ;;
esac
}