-
Notifications
You must be signed in to change notification settings - Fork 38
π Supervise background processes in AuthBridge entrypoints #308
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 |
|---|---|---|
| @@ -1,13 +1,37 @@ | ||
| #!/bin/sh | ||
| #!/bin/bash | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must-fix: Two options:
Option 1 is simpler but adds ~5MB to the image. Option 2 keeps the minimal image but is more complex.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Verified end-to-end on a Kind cluster: built the image, deployed the quickstart demo, confirmed both processes start under the supervision loop, killed |
||
| set -eu | ||
|
|
||
| # Start the go-processor in the background | ||
| # Envoy + go-processor entrypoint with process supervision. | ||
| # Both processes run in the background; the shell stays as PID 1. | ||
| # If either process exits, the other is killed and the container exits | ||
| # non-zero so Kubernetes restarts it. | ||
|
|
||
| cleanup() { | ||
| echo "Received signal, shutting down..." | ||
| kill "$GO_PROCESSOR_PID" "$ENVOY_PID" 2>/dev/null || true | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. must-fix: Initialize both to empty before the trap, matching the GO_PROCESSOR_PID=""
ENVOY_PID=""
cleanup() {
...
}
trap cleanup TERM INT |
||
| wait | ||
| exit 0 | ||
| } | ||
| trap cleanup TERM INT | ||
|
|
||
| # Start go-processor in the background | ||
| echo "Starting go-processor..." | ||
| /usr/local/bin/go-processor & | ||
| GO_PROCESSOR_PID=$! | ||
|
|
||
| # Give go-processor a moment to start | ||
| sleep 2 | ||
|
|
||
| # Start Envoy in the foreground | ||
| # Start Envoy in the background (not exec β shell must stay PID 1 for supervision) | ||
| echo "Starting Envoy..." | ||
| exec /usr/local/bin/envoy -c /etc/envoy/envoy.yaml --service-cluster auth-proxy --service-node auth-proxy --log-level debug | ||
| /usr/local/bin/envoy -c /etc/envoy/envoy.yaml \ | ||
| --service-cluster auth-proxy --service-node auth-proxy --log-level debug & | ||
| ENVOY_PID=$! | ||
|
|
||
| # Wait for the first child to exit. If either process dies, restart the container. | ||
| wait -n "$GO_PROCESSOR_PID" "$ENVOY_PID" | ||
| EXIT_CODE=$? | ||
| echo "A process exited unexpectedly (exit code $EXIT_CODE), terminating container" | ||
| kill "$GO_PROCESSOR_PID" "$ENVOY_PID" 2>/dev/null || true | ||
| wait | ||
| exit 1 | ||
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.
π Clean pattern β
CRITICAL_PIDSaccumulation,wait -n, trap withcleanup. Client-registration correctly excluded from monitoring. The${SPIRE_ENABLED:-}default is a good defensive fix too.