#!/usr/bin/env bash # Wrapper used by the LaunchAgent. On every (re)start: # 1. Pull latest source from git (if remote is reachable) # 2. Rebuild the release binary # 3. Exec the new binary # # This ensures the service always runs the latest code after a restart, # eliminating drift between the checked-out source and the running binary. set -e cd "$(dirname "$0")/.." ROOT="$(pwd)" LOG="${ROOT}/logs/launch-wrapper.log" mkdir -p "${ROOT}/logs" log() { echo "[$(date '+%Y-%m-%d %H:%M:%S')] $*" >> "$LOG"; } log "=== launch-wrapper starting ===" # Pull latest (best-effort; offline is fine) if git pull --ff-only origin master >> "$LOG" 2>&1; then log "git pull succeeded" else log "git pull skipped (offline or conflict)" fi # Rebuild log "building release binary..." if cargo build --release >> "$LOG" 2>&1; then log "build succeeded" else log "ERROR: build failed, running existing binary" fi log "exec camera-qrng" exec "${ROOT}/target/release/camera-qrng"