-
Notifications
You must be signed in to change notification settings - Fork 0
Auto-find available port and version-check running instances #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -80,13 +80,29 @@ runs: | |||||
| run: | | ||||||
| set -euo pipefail | ||||||
|
|
||||||
| ENDPOINT="http://${SPICEIO_BIND}" | ||||||
|
|
||||||
| # Skip if spiceio is already listening on the requested address | ||||||
| if curl -sf -I "$ENDPOINT/" 2>/dev/null | grep -qi "server: spiceio"; then | ||||||
| echo "spiceio already running at $ENDPOINT — skipping start" | ||||||
| echo "endpoint=$ENDPOINT" >> "$GITHUB_OUTPUT" | ||||||
| exit 0 | ||||||
| # Check if spiceio is already listening on the requested address | ||||||
| WANT_VERSION=$(spiceio --version | awk '{print $2}') | ||||||
| RUNNING_HEADER=$(curl -sf -I "http://${SPICEIO_BIND}/" 2>/dev/null | grep -i '^server:.*spiceio' | tr -d '\r' || true) | ||||||
| if [[ -n "$RUNNING_HEADER" ]]; then | ||||||
| # Extract version from "Server: spiceio/X.Y.Z"; bare "Server: spiceio" | ||||||
| # (no slash) means a pre-versioned build — treat as outdated. | ||||||
| RUNNING_VERSION="${RUNNING_HEADER##*/}" | ||||||
| RUNNING_VERSION="${RUNNING_VERSION// /}" | ||||||
| if [[ "$RUNNING_HEADER" == */* && "$RUNNING_VERSION" == "$WANT_VERSION" ]]; then | ||||||
| echo "spiceio $WANT_VERSION already running at http://${SPICEIO_BIND} — skipping start" | ||||||
| echo "endpoint=http://${SPICEIO_BIND}" >> "$GITHUB_OUTPUT" | ||||||
| exit 0 | ||||||
| fi | ||||||
| # Old or mismatched version — kill it so we can replace it | ||||||
| mapfile -t OLD_PIDS < <(lsof -ti "tcp:${SPICEIO_BIND##*:}" -sTCP:LISTEN 2>/dev/null || true) | ||||||
| if (( ${#OLD_PIDS[@]} > 0 )); then | ||||||
| echo "replacing spiceio ${RUNNING_VERSION:-unknown} (PID(s) ${OLD_PIDS[*]}) with $WANT_VERSION" | ||||||
| kill "${OLD_PIDS[@]}" 2>/dev/null || true | ||||||
| for i in $(seq 1 10); do | ||||||
| lsof -ti "tcp:${SPICEIO_BIND##*:}" -sTCP:LISTEN >/dev/null 2>&1 || break | ||||||
| sleep 1 | ||||||
|
Comment on lines
+96
to
+103
|
||||||
| done | ||||||
| fi | ||||||
| fi | ||||||
|
|
||||||
| # Parse smb://user:pass@server:port/share | ||||||
|
|
@@ -127,21 +143,28 @@ runs: | |||||
| export SPICEIO_SMB_SERVER SPICEIO_SMB_PORT SPICEIO_SMB_USER SPICEIO_SMB_PASS SPICEIO_SMB_SHARE | ||||||
| export SPICEIO_BUCKET SPICEIO_REGION SPICEIO_BIND | ||||||
|
|
||||||
| SPICEIO_LOG="${RUNNER_TEMP}/spiceio.log" | ||||||
| : > "$SPICEIO_LOG" | ||||||
| export SPICEIO_LOG_FILE="$SPICEIO_LOG" | ||||||
|
|
||||||
| spiceio & | ||||||
| PID=$! | ||||||
| echo "endpoint=$ENDPOINT" >> "$GITHUB_OUTPUT" | ||||||
|
|
||||||
| # Wait for readiness | ||||||
| # Wait for spiceio to report its actual listening address (port may | ||||||
| # auto-increment if the requested port was busy). | ||||||
| echo "Waiting for spiceio on ${SPICEIO_BIND}..." | ||||||
| ENDPOINT="" | ||||||
| for i in $(seq 1 30); do | ||||||
| if curl -sf -o /dev/null "$ENDPOINT/" 2>/dev/null; then | ||||||
| echo "spiceio ready at $ENDPOINT (PID $PID)" | ||||||
| exit 0 | ||||||
| fi | ||||||
| if ! kill -0 "$PID" 2>/dev/null; then | ||||||
| echo "::error::spiceio exited unexpectedly" | ||||||
| exit 1 | ||||||
| fi | ||||||
| ENDPOINT=$(grep 'listening on' "$SPICEIO_LOG" 2>/dev/null | grep -o 'http://[^ ]*' | tail -1 || true) | ||||||
| if [[ -n "$ENDPOINT" ]] && curl -sf -I "$ENDPOINT/" 2>/dev/null | grep -qi "server: spiceio"; then | ||||||
|
lukekim marked this conversation as resolved.
|
||||||
| if [[ -n "$ENDPOINT" ]] && curl -sf -I "$ENDPOINT/" 2>/dev/null | grep -qi "server: spiceio"; then | |
| if [[ -n "$ENDPOINT" ]] && curl -sS -D - -o /dev/null "$ENDPOINT/" 2>/dev/null | grep -qi '^server: spiceio'; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curl -sf -I "http://${SPICEIO_BIND}/"uses HEAD on/. The router returns 405 for service-level requests that are not GET (seesrc/s3/router.rsaround thereq_bucket.is_empty()match), and-fsuppresses headers on 4xx, soRUNNING_HEADERwill usually be empty and the version/skip logic won’t trigger. Use a GET request when checking headers (e.g., request/and capture response headers) or remove-f/target a path that supports HEAD (like/$SPICEIO_BUCKET).