-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from keveinliu/image-tool
[feat] Sidecar image tool
- Loading branch information
Showing
4 changed files
with
102 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
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
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,7 @@ | ||
#!/usr/bin/env sh | ||
|
||
#Gracefully kill sidecar. | ||
#Pipy won't accept new connections when receiving SIGINT signal | ||
#And quit after all connections are closed. | ||
|
||
kill -SIGINT 1 |
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,93 @@ | ||
#!/usr/bin/env sh | ||
|
||
# Default values | ||
DEFAULT_URL="http://127.0.0.1:15000/config_dump" | ||
DEFAULT_REQ_TMOUT=1 # Single request timeout in seconds | ||
DEFAULT_INTERVAL=1 # Interval between requests in seconds | ||
DEFAULT_TIMEOUT=60 # Total timeout in seconds | ||
|
||
# Display usage | ||
usage() { | ||
echo "Usage: $0 [options]" | ||
echo "Options:" | ||
echo " -u, --url URL URL to check (default: $DEFAULT_URL)" | ||
echo " -r, --req-tmout SEC Single request timeout in seconds (default: $DEFAULT_REQ_TMOUT)" | ||
echo " -i, --interval SEC Interval between requests in seconds (default: $DEFAULT_INTERVAL)" | ||
echo " -t, --timeout SEC Total timeout in seconds (default: $DEFAULT_TIMEOUT)" | ||
echo " -h, --help Show this help message" | ||
} | ||
|
||
# Initialize variables with default values | ||
URL=$DEFAULT_URL | ||
REQ_TMOUT=$DEFAULT_REQ_TMOUT | ||
INTERVAL=$DEFAULT_INTERVAL | ||
TIMEOUT=$DEFAULT_TIMEOUT | ||
|
||
# Parse command line arguments | ||
while [[ $# -gt 0 ]]; do | ||
case $1 in | ||
-u|--url) | ||
URL="$2" | ||
shift 2 | ||
;; | ||
-r|--req-tmout) | ||
REQ_TMOUT="$2" | ||
shift 2 | ||
;; | ||
-i|--interval) | ||
INTERVAL="$2" | ||
shift 2 | ||
;; | ||
-t|--timeout) | ||
TIMEOUT="$2" | ||
shift 2 | ||
;; | ||
-h|--help) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
echo "Unknown parameter: $1" | ||
usage | ||
exit 1 | ||
;; | ||
esac | ||
done | ||
|
||
# Calculate start time | ||
start_time=$(date +%s) | ||
|
||
echo "Starting HTTP service check..." | ||
echo "URL: $URL" | ||
echo "Single request timeout (REQ_TMOUT): $REQ_TMOUT seconds" | ||
echo "Request interval (INTERVAL): $INTERVAL seconds" | ||
echo "Total timeout (TIMEOUT): $TIMEOUT seconds" | ||
|
||
while true; do | ||
# Check if total timeout is exceeded | ||
current_time=$(date +%s) | ||
elapsed=$((current_time - start_time)) | ||
|
||
if [ $elapsed -ge $TIMEOUT ]; then | ||
echo "Total timeout of $TIMEOUT seconds reached. Service check failed!" | ||
exit 1 | ||
fi | ||
|
||
# Send HTTP request | ||
response=$(curl -s -o /dev/null -w "%{http_code}" \ | ||
--connect-timeout $REQ_TMOUT \ | ||
--max-time $REQ_TMOUT \ | ||
"$URL" 2>/dev/null) | ||
|
||
if [ "$response" = "200" ]; then | ||
echo "HTTP service is ready!" | ||
echo "Total time elapsed: $elapsed seconds" | ||
exit 0 | ||
else | ||
echo "Service not ready, HTTP status code: $response" | ||
echo "Time elapsed: $elapsed seconds, timeout: $TIMEOUT seconds" | ||
echo "Waiting $INTERVAL seconds before next attempt..." | ||
sleep $INTERVAL | ||
fi | ||
done | ||
|