André Amorim

Crafting Web Experiences


//

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


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

done

Published date:

Modified date: