Skip to content

Instantly share code, notes, and snippets.

@swashcap
Created March 9, 2019 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swashcap/b0f240c38933fa18130130b13ff85982 to your computer and use it in GitHub Desktop.
Save swashcap/b0f240c38933fa18130130b13ff85982 to your computer and use it in GitHub Desktop.
Server Startup Time
#!/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