Skip to content

Instantly share code, notes, and snippets.

@swashcap swashcap/startup.sh
Created Mar 9, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.