Fix LXC config modification for Proxmox pmxcfs filesystem
The /etc/pve/ directory is a clustered FUSE filesystem (pmxcfs) managed by Proxmox. Direct modifications using sed -i or echo >> don't work reliably on this filesystem, and LXC config files contain snapshot sections that must be preserved. Changes: - Use temp file approach: copy config, modify temp, copy back to trigger sync - Only modify main config section (before first [snapshot] marker) - Properly handle both mp mount removal and lxc.mount.entry addition - Apply fix to both install.sh and install-sensor-proxy.sh This fixes temperature proxy setup failures where the socket mount entry wasn't being persisted to the container configuration. Related to #628
This commit is contained in:
parent
9b50dec0e4
commit
080453b68a
2 changed files with 69 additions and 12 deletions
40
install.sh
40
install.sh
|
|
@ -457,22 +457,50 @@ configure_proxy_socket_mount() {
|
|||
|
||||
local updated=false
|
||||
|
||||
if grep -Eq '^mp[0-9]+: .*pulse-sensor-proxy' "$lxc_config" 2>/dev/null; then
|
||||
# /etc/pve is a FUSE filesystem (pmxcfs) - direct sed/echo don't work reliably
|
||||
# Must use temp file and copy back to trigger cluster sync
|
||||
# Also, config file contains snapshots sections - only modify main section (before first [)
|
||||
local temp_config=$(mktemp)
|
||||
cp "$lxc_config" "$temp_config"
|
||||
|
||||
# Extract line number where snapshots start (first line starting with [)
|
||||
local snapshot_start=$(grep -n '^\[' "$temp_config" | head -1 | cut -d: -f1)
|
||||
|
||||
if grep -Eq '^mp[0-9]+: .*pulse-sensor-proxy' "$temp_config" 2>/dev/null; then
|
||||
print_info "Removing mp entries for pulse-sensor-proxy to keep snapshots and migrations working"
|
||||
sed -i '/^mp[0-9]\+: .*pulse-sensor-proxy/d' "$lxc_config"
|
||||
if [ -n "$snapshot_start" ]; then
|
||||
sed -i "1,$((snapshot_start-1)) { /^mp[0-9]\+: .*pulse-sensor-proxy/d }" "$temp_config"
|
||||
else
|
||||
sed -i '/^mp[0-9]\+: .*pulse-sensor-proxy/d' "$temp_config"
|
||||
fi
|
||||
updated=true
|
||||
fi
|
||||
|
||||
if grep -q "^lxc.mount.entry: .*/pulse-sensor-proxy" "$lxc_config" 2>/dev/null; then
|
||||
if ! grep -qxF "$desired_entry" "$lxc_config"; then
|
||||
sed -i "s#^lxc.mount.entry: .*pulse-sensor-proxy.*#${desired_entry}#" "$lxc_config"
|
||||
if grep -q "^lxc.mount.entry: .*/pulse-sensor-proxy" "$temp_config" 2>/dev/null; then
|
||||
if ! grep -qxF "$desired_entry" "$temp_config"; then
|
||||
if [ -n "$snapshot_start" ]; then
|
||||
sed -i "1,$((snapshot_start-1)) { s#^lxc.mount.entry: .*pulse-sensor-proxy.*#${desired_entry}# }" "$temp_config"
|
||||
else
|
||||
sed -i "s#^lxc.mount.entry: .*pulse-sensor-proxy.*#${desired_entry}#" "$temp_config"
|
||||
fi
|
||||
updated=true
|
||||
fi
|
||||
else
|
||||
echo "$desired_entry" >> "$lxc_config"
|
||||
# Insert before snapshot section if it exists, otherwise append
|
||||
if [ -n "$snapshot_start" ]; then
|
||||
sed -i "${snapshot_start}i ${desired_entry}" "$temp_config"
|
||||
else
|
||||
echo "$desired_entry" >> "$temp_config"
|
||||
fi
|
||||
updated=true
|
||||
fi
|
||||
|
||||
# Copy back to trigger pmxcfs sync
|
||||
if [[ "$updated" == true ]]; then
|
||||
cp "$temp_config" "$lxc_config"
|
||||
fi
|
||||
rm -f "$temp_config"
|
||||
|
||||
if ! pct config "$ctid" | grep -qxF "$desired_entry"; then
|
||||
print_error "Failed to persist pulse-sensor-proxy mount entry in $lxc_config"
|
||||
return 1
|
||||
|
|
|
|||
|
|
@ -3157,26 +3157,55 @@ if [[ "$STANDALONE" == false ]]; then
|
|||
CT_RUNNING=true
|
||||
fi
|
||||
|
||||
if grep -Eq '^mp[0-9]+: .*pulse-sensor-proxy' "$LXC_CONFIG" 2>/dev/null; then
|
||||
# /etc/pve is a FUSE filesystem (pmxcfs) - direct sed/echo don't work reliably
|
||||
# Must use temp file and copy back to trigger cluster sync
|
||||
# Also, config file contains snapshots sections - only modify main section (before first [)
|
||||
TEMP_CONFIG=$(mktemp)
|
||||
cp "$LXC_CONFIG" "$TEMP_CONFIG"
|
||||
|
||||
# Extract line number where snapshots start (first line starting with [)
|
||||
SNAPSHOT_START=$(grep -n '^\[' "$TEMP_CONFIG" | head -1 | cut -d: -f1)
|
||||
|
||||
if grep -Eq '^mp[0-9]+: .*pulse-sensor-proxy' "$TEMP_CONFIG" 2>/dev/null; then
|
||||
print_info "Removing mp mounts for pulse-sensor-proxy to keep snapshots and migrations working"
|
||||
sed -i '/^mp[0-9]\+: .*pulse-sensor-proxy/d' "$LXC_CONFIG"
|
||||
if [ -n "$SNAPSHOT_START" ]; then
|
||||
# Only modify main section (before snapshots)
|
||||
sed -i "1,$((SNAPSHOT_START-1)) { /^mp[0-9]\+: .*pulse-sensor-proxy/d }" "$TEMP_CONFIG"
|
||||
else
|
||||
sed -i '/^mp[0-9]\+: .*pulse-sensor-proxy/d' "$TEMP_CONFIG"
|
||||
fi
|
||||
MOUNT_UPDATED=true
|
||||
fi
|
||||
|
||||
if grep -q "^lxc.mount.entry: .*/pulse-sensor-proxy" "$LXC_CONFIG" 2>/dev/null; then
|
||||
if ! grep -qxF "$LOCAL_MOUNT_ENTRY" "$LXC_CONFIG"; then
|
||||
if grep -q "^lxc.mount.entry: .*/pulse-sensor-proxy" "$TEMP_CONFIG" 2>/dev/null; then
|
||||
if ! grep -qxF "$LOCAL_MOUNT_ENTRY" "$TEMP_CONFIG"; then
|
||||
print_info "Updating existing lxc.mount.entry for pulse-sensor-proxy"
|
||||
sed -i "s#^lxc.mount.entry: .*pulse-sensor-proxy.*#${LOCAL_MOUNT_ENTRY}#" "$LXC_CONFIG"
|
||||
if [ -n "$SNAPSHOT_START" ]; then
|
||||
sed -i "1,$((SNAPSHOT_START-1)) { s#^lxc.mount.entry: .*pulse-sensor-proxy.*#${LOCAL_MOUNT_ENTRY}# }" "$TEMP_CONFIG"
|
||||
else
|
||||
sed -i "s#^lxc.mount.entry: .*pulse-sensor-proxy.*#${LOCAL_MOUNT_ENTRY}#" "$TEMP_CONFIG"
|
||||
fi
|
||||
MOUNT_UPDATED=true
|
||||
else
|
||||
print_info "Container already has migration-safe lxc.mount.entry for proxy"
|
||||
fi
|
||||
else
|
||||
print_info "Adding lxc.mount.entry for pulse-sensor-proxy"
|
||||
echo "$LOCAL_MOUNT_ENTRY" >> "$LXC_CONFIG"
|
||||
# Insert before snapshot section if it exists, otherwise append
|
||||
if [ -n "$SNAPSHOT_START" ]; then
|
||||
sed -i "${SNAPSHOT_START}i ${LOCAL_MOUNT_ENTRY}" "$TEMP_CONFIG"
|
||||
else
|
||||
echo "$LOCAL_MOUNT_ENTRY" >> "$TEMP_CONFIG"
|
||||
fi
|
||||
MOUNT_UPDATED=true
|
||||
fi
|
||||
|
||||
# Copy back to trigger pmxcfs sync
|
||||
if [[ "$MOUNT_UPDATED" = true ]]; then
|
||||
cp "$TEMP_CONFIG" "$LXC_CONFIG"
|
||||
fi
|
||||
rm -f "$TEMP_CONFIG"
|
||||
|
||||
if ! pct config "$CTID" | grep -qxF "$LOCAL_MOUNT_ENTRY"; then
|
||||
print_error "Failed to persist migration-safe socket mount in container config"
|
||||
if [ -n "$LXC_CONFIG_BACKUP" ] && [ -f "$LXC_CONFIG_BACKUP" ]; then
|
||||
|
|
|
|||
Loading…
Reference in a new issue