Created
March 9, 2019 22:07
-
-
Save swashcap/b0f240c38933fa18130130b13ff85982 to your computer and use it in GitHub Desktop.
Server Startup Time
This file contains hidden or 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
#!/bin/bash | |
set -eo pipefail | |
# | |
# Test server startup times using crude scripting | |
# | |
# Use: | |
# | |
# time CMD="npm start" URL=localhost:3000 ./startup.sh | |
# | |
START_TIME=$(date +%s) | |
RETRY_COUNT=0 | |
bash -c "$CMD" &> /dev/null & | |
while [ "$(curl -fks "$URL" &> /dev/null; echo $?)" -gt 0 ] && [ "$RETRY_COUNT" -lt 1000 ]; do | |
RETRY_COUNT=$((RETRY_COUNT + 1)) | |
sleep 0.1 | |
done | |
END_TIME=$(date +%s) | |
echo "Duration: $(bc <<< "$END_TIME - $START_TIME") seconds" | |
kill -9 $! # stop background command |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment