diff --git a/tools/utun_update.sh b/tools/utun_update.sh index 2319b55d..c5432194 100755 --- a/tools/utun_update.sh +++ b/tools/utun_update.sh @@ -65,6 +65,9 @@ if [ -f "$PIDFILE" ]; then rm -f "$PIDFILE" fi +# Ensure pidfile is removed before start +rm -f "$PIDFILE" + # Git pull echo "Pulling latest changes..." if ! git pull; then @@ -107,8 +110,22 @@ echo "Build successful: $(ls -la $UTUN_BIN)" # Start utun echo "Starting utun..." nohup "$UTUN_BIN" > utun_cons.log 2> utun_err.log & -NEW_PID=$! -sleep 2 + +# Wait for pidfile to be created (up to 10s) +for i in 1 2 3 4 5 6 7 8 9 10; do + if [ -f "$PIDFILE" ]; then + break + fi + sleep 1 +done + +# Read PID from file +if [ -f "$PIDFILE" ]; then + NEW_PID=$(cat "$PIDFILE") +else + echo "ERROR: Failed to start utun (pidfile not created)" >&2 + exit 4 +fi # Verify process is running if kill -0 "$NEW_PID" 2>/dev/null; then