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.
This commit is contained in:
rcourtman 2025-11-19 11:04:58 +00:00
parent a24e9053d1
commit 879de50131

View file

@ -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