Created
May 31, 2017 08:17
-
-
Save dohzya/c867c959e1c60bd2ad5b5263442fe2db to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
debug="${DEBUG:-false}" | |
if [[ "$1" == "-d" ]]; then debug="true"; fi | |
timeout="${TIMEOUT:-300}" # 5 minutes | |
sleep_time="${SLEEP:-1}" # 1 second | |
check_docker_running() { | |
docker system info >/dev/null 2>&1 | |
} | |
log() { | |
[[ "$debug" != "true" ]] || echo "$@" | |
} | |
current_ts() { | |
date +%s | |
} | |
if check_docker_running; then | |
log "Docker already running" | |
else | |
log "Start Docker" | |
open /Applications/Docker.app | |
log "Wait for Docker to be started" | |
start=$(current_ts) | |
while ! check_docker_running; do | |
now=$(current_ts) | |
duration=$(( now - start )) | |
log " duration=$duration" | |
if (( duration > timeout )); then | |
echo "Wait for too long (${duration}s, timeout was ${timeout}s), stop here" >&2 | |
exit 3 | |
fi | |
sleep "$sleep_time" | |
done | |
log "Docker started" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment