diff mbox

docker: increase database connection timeout

Message ID 20170525053618.6125-1-andrew.donnellan@au1.ibm.com
State Accepted
Headers show

Commit Message

Andrew Donnellan May 25, 2017, 5:36 a.m. UTC
When starting the Docker environment, if the web container can't see the
database immediately, it waits 5 seconds, tries again, then waits 15
seconds more to account for first-time start-ups where it takes a bit
longer for the database to be initialised.

Some of us, unfortunately, have slow computers with slow mechanical hard
drives which take just a bit longer. Increase the second timeout from 15
seconds to 60 seconds, testing every 5 seconds.

Cc: Daniel Axtens <dja@axtens.net>
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 tools/docker/entrypoint.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Daniel Axtens May 25, 2017, 6:01 a.m. UTC | #1
Andrew Donnellan <andrew.donnellan@au1.ibm.com> writes:

> When starting the Docker environment, if the web container can't see the
> database immediately, it waits 5 seconds, tries again, then waits 15
> seconds more to account for first-time start-ups where it takes a bit
> longer for the database to be initialised.
>
> Some of us, unfortunately, have slow computers with slow mechanical hard
> drives which take just a bit longer. Increase the second timeout from 15
> seconds to 60 seconds, testing every 5 seconds.
>
> Cc: Daniel Axtens <dja@axtens.net>
Acked-by: Daniel Axtens <dja@axtens.net>

LGTM - thanks Andrew for the fix and the reminder we don't all have
PCI-connected NVMe :P

Regards,
Daniel
> Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
> ---
>  tools/docker/entrypoint.sh | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh
> index 5a23fa3..949d8af 100755
> --- a/tools/docker/entrypoint.sh
> +++ b/tools/docker/entrypoint.sh
> @@ -53,8 +53,13 @@ if ! test_db_connection; then
>      sleep 5
>      if ! test_db_connection; then
>          echo "Still cannot connect to MySQL."
> -        echo "Maybe you are starting the db for the first time. Waiting 15 seconds."
> -        sleep 15
> +        echo "Maybe you are starting the db for the first time. Waiting up to 60 seconds."
> +        for i in {0..9}; do
> +            sleep 5
> +            if test_db_connection; then
> +                break
> +            fi
> +        done
>          if ! test_db_connection; then
>              echo "Still cannot connect to MySQL. Giving up."
>              echo "Are you using docker-compose? If not, have you set up the link correctly?"
> -- 
> Andrew Donnellan              OzLabs, ADL Canberra
> andrew.donnellan@au1.ibm.com  IBM Australia Limited
Stephen Finucane May 26, 2017, 8:45 a.m. UTC | #2
On Thu, 2017-05-25 at 16:01 +1000, Daniel Axtens wrote:
> Andrew Donnellan <andrew.donnellan@au1.ibm.com> writes:
> 
> > When starting the Docker environment, if the web container can't
> > see the
> > database immediately, it waits 5 seconds, tries again, then waits
> > 15
> > seconds more to account for first-time start-ups where it takes a
> > bit
> > longer for the database to be initialised.
> > 
> > Some of us, unfortunately, have slow computers with slow mechanical
> > hard
> > drives which take just a bit longer. Increase the second timeout
> > from 15
> > seconds to 60 seconds, testing every 5 seconds.
> > 
> > Cc: Daniel Axtens <dja@axtens.net>
> 
> Acked-by: Daniel Axtens <dja@axtens.net>
> 
> LGTM - thanks Andrew for the fix and the reminder we don't all have
> PCI-connected NVMe :P

Boo spinning rust.

Reviewed-by: Stephen Finucane <stephen@that.guru>

and applied.

Stephen
diff mbox

Patch

diff --git a/tools/docker/entrypoint.sh b/tools/docker/entrypoint.sh
index 5a23fa3..949d8af 100755
--- a/tools/docker/entrypoint.sh
+++ b/tools/docker/entrypoint.sh
@@ -53,8 +53,13 @@  if ! test_db_connection; then
     sleep 5
     if ! test_db_connection; then
         echo "Still cannot connect to MySQL."
-        echo "Maybe you are starting the db for the first time. Waiting 15 seconds."
-        sleep 15
+        echo "Maybe you are starting the db for the first time. Waiting up to 60 seconds."
+        for i in {0..9}; do
+            sleep 5
+            if test_db_connection; then
+                break
+            fi
+        done
         if ! test_db_connection; then
             echo "Still cannot connect to MySQL. Giving up."
             echo "Are you using docker-compose? If not, have you set up the link correctly?"