Docker WordPress MySQL Container Health Check in Bash via WP-CLI

# In seconds
timeout=60
wait=2

try=0
is_ready=false
printf "Waiting MySQL to initialize ..."
while [[ $is_ready == false ]] && [[ $try -lt $timeout ]];do

    let try=try+wait

    if wp --allow-root --skip-plugins --skip-themes --skip-packages db check &>/dev/null;then
        is_ready=true
        echo " started"
    elif [[ $try -ge $timeout ]];then
        echo " timeout"
        exit 1
    else
        printf "."
        sleep $wait
    fi

doneCode language: Bash (bash)

Posted

in

, , ,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.