-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add long running central port-forward script
- Loading branch information
1 parent
83d0b80
commit 94d0465
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# Function to start port forwarding | ||
start_port_forward() { | ||
kubectl -n stackrox port-forward svc/central 8000:443 & | ||
# Capture the process ID of the background process | ||
PORT_FORWARD_PID=$! | ||
wait $PORT_FORWARD_PID | ||
} | ||
|
||
# Function to check the connection | ||
check_connection() { | ||
while true; do | ||
# Use curl to ping the endpoint | ||
if curl -sSf http://localhost:8000 > /dev/null; then | ||
echo "Connection is active." | ||
else | ||
echo "Connection lost. Restarting port forward..." | ||
# If the connection is lost, kill the port forward process | ||
kill $PORT_FORWARD_PID | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
} | ||
|
||
# Main loop | ||
while true; do | ||
echo "Starting port forward..." | ||
start_port_forward | ||
|
||
# Start the connection check in the background | ||
check_connection & | ||
|
||
# Wait for the port forward process to exit | ||
wait $PORT_FORWARD_PID | ||
|
||
# If the process exits, wait for a few seconds and restart | ||
echo "Port forward process exited. Restarting in 5 seconds..." | ||
sleep 5 | ||
done |