Skip to content

Instantly share code, notes, and snippets.

@ErikFontanel
Created August 31, 2018 12:40
Show Gist options
  • Save ErikFontanel/ab80f4b2b6abb64f2a6dfe87b5526198 to your computer and use it in GitHub Desktop.
Save ErikFontanel/ab80f4b2b6abb64f2a6dfe87b5526198 to your computer and use it in GitHub Desktop.
Start docker daemon if it's not already when docker-compose up is ran
#!/bin/bash
# spinner
# @see https://stackoverflow.com/questions/238073/how-to-add-a-progress-bar-to-a-shell-script
sp="/-\|"
sc=0
spin() {
printf "\b${sp:sc++:1}"
((sc==${#sp})) && sc=0
}
endspin() {
printf "\r%s\n" "$@"
}
# Check if Docker is running, if not, launch and wait for ready
startdocker() {
if ! docker system info; then
echo -e "\e[36mLaunching Docker…\e[0m";
open --background -a Docker;
while ! docker system info > /dev/null 2>&1;
spin
do sleep 1;
done
endspin
fi
}
# Start project
up() {
startdocker;
if [[ -n $1 ]]; then
cd $SITES/$1 || return;
fi
docker-compose up -d;
}
down() {
if [[ -n $1 ]]; then
cd $SITES/$1 || return;
fi
docker-compose down;
}
restart() {
if [[ -n $1 ]]; then
cd $SITES/$1 || return;
fi
docker-compose restart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment