From 879de50131ec9b4a06db2363edc9864241ea5076 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Wed, 19 Nov 2025 11:04:58 +0000 Subject: [PATCH] fix(sensor-proxy): eliminate race in migration script Stop pulse-sensor-proxy service before modifying config.yaml to prevent races with the running daemon or concurrent CLI commands. The migration script now: 1. Stops service if running 2. Updates config atomically (temp + rename in same directory) 3. Restarts service if it was running This achieves complete architectural isolation - ALL config file writers are now coordinated (either through Phase 2 CLI locking or by ensuring the service is stopped during modification). Addresses final Codex review feedback. --- scripts/migrate-sensor-proxy-control-plane.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/scripts/migrate-sensor-proxy-control-plane.sh b/scripts/migrate-sensor-proxy-control-plane.sh index 7fffe07..49fe10d 100644 --- a/scripts/migrate-sensor-proxy-control-plane.sh +++ b/scripts/migrate-sensor-proxy-control-plane.sh @@ -148,12 +148,22 @@ EOF chown pulse-sensor-proxy:pulse-sensor-proxy "$CONFIG_FILE" 2>/dev/null || true } +log "Stopping service to prevent config file races..." +if systemctl is-active --quiet pulse-sensor-proxy; then + systemctl stop pulse-sensor-proxy + SERVICE_WAS_RUNNING=true +else + SERVICE_WAS_RUNNING=false +fi + log "Updating config..." update_config_atomically -if [[ "$SKIP_RESTART" == false ]]; then - log "Restarting pulse-sensor-proxy..." - systemctl restart pulse-sensor-proxy +if [[ "$SKIP_RESTART" == false ]] && [[ "$SERVICE_WAS_RUNNING" == true ]]; then + log "Starting pulse-sensor-proxy..." + systemctl start pulse-sensor-proxy +elif [[ "$SERVICE_WAS_RUNNING" == false ]]; then + log "Service was not running; leaving stopped" else warn "Skipping service restart; control-plane sync will start on next restart" fi