From e82b6080afa6b11dfdcb8323293ee84d56bf5f88 Mon Sep 17 00:00:00 2001 From: Daniel Genezini Date: Mon, 8 May 2023 20:09:38 -0300 Subject: [PATCH 1/4] Fix configure-db.sh script --- .../examples/mssql-customize/configure-db.sh | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/linux/preview/examples/mssql-customize/configure-db.sh b/linux/preview/examples/mssql-customize/configure-db.sh index be49de93..5f623d4c 100644 --- a/linux/preview/examples/mssql-customize/configure-db.sh +++ b/linux/preview/examples/mssql-customize/configure-db.sh @@ -1,26 +1,29 @@ #!/bin/bash -# Wait 60 seconds for SQL Server to start up by ensuring that -# calling SQLCMD does not return an error code, which will ensure that sqlcmd is accessible -# and that system and user databases return "0" which means all databases are in an "online" state +# Calls SQLCMD to verify that system and user databases return "0" which means all databases are in an "online" state, +# then run the configuration script (setup.sql) # https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/sys-databases-transact-sql?view=sql-server-2017 +TRIES=60 DBSTATUS=1 ERRCODE=1 i=0 -while [[ $DBSTATUS -ne 0 ]] && [[ $i -lt 60 ]] && [[ $ERRCODE -ne 0 ]]; do - i=$i+1 - DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P $SA_PASSWORD -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases") - ERRCODE=$? +while [[ $DBSTATUS -ne 0 ]] && [[ $i -lt $TRIES ]]; do + i=$((i+1)) + DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P $MSSQL_SA_PASSWORD -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases" > /dev/null 2>&1) || DBSTATUS=1 + sleep 1 done -if [ $DBSTATUS -ne 0 ] OR [ $ERRCODE -ne 0 ]; then - echo "SQL Server took more than 60 seconds to start up or one or more databases are not in an ONLINE state" +if [ $DBSTATUS -ne 0 ]; then + echo "SQL Server took more than $TRIES seconds to start up or one or more databases are not in an ONLINE state" exit 1 fi # Run the setup script to create the DB and the schema in the DB -/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -d master -i setup.sql +echo "Running configuration script..." +/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $MSSQL_SA_PASSWORD -d master -i setup.sql + +echo "Configuration completed." From d1a2572485ffadb9b0ce5219ae9c91f04eda5b63 Mon Sep 17 00:00:00 2001 From: Daniel Genezini Date: Mon, 8 May 2023 20:13:07 -0300 Subject: [PATCH 2/4] Explicit sleep unit --- linux/preview/examples/mssql-customize/configure-db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/preview/examples/mssql-customize/configure-db.sh b/linux/preview/examples/mssql-customize/configure-db.sh index 5f623d4c..b729bef7 100644 --- a/linux/preview/examples/mssql-customize/configure-db.sh +++ b/linux/preview/examples/mssql-customize/configure-db.sh @@ -13,7 +13,7 @@ while [[ $DBSTATUS -ne 0 ]] && [[ $i -lt $TRIES ]]; do i=$((i+1)) DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P $MSSQL_SA_PASSWORD -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases" > /dev/null 2>&1) || DBSTATUS=1 - sleep 1 + sleep 1s done if [ $DBSTATUS -ne 0 ]; then From f7e21edafbd1c3cc93b4f07e45e34806ca168b86 Mon Sep 17 00:00:00 2001 From: Daniel Genezini Date: Tue, 9 May 2023 18:48:39 -0300 Subject: [PATCH 3/4] Removing chmod commands from Dockerfile --- linux/preview/examples/mssql-customize/Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/linux/preview/examples/mssql-customize/Dockerfile b/linux/preview/examples/mssql-customize/Dockerfile index e12d9270..a430430c 100644 --- a/linux/preview/examples/mssql-customize/Dockerfile +++ b/linux/preview/examples/mssql-customize/Dockerfile @@ -7,8 +7,4 @@ WORKDIR /usr/config # Bundle config source COPY . /usr/config -# Grant permissions for to our scripts to be executable -RUN chmod +x /usr/config/entrypoint.sh -RUN chmod +x /usr/config/configure-db.sh - ENTRYPOINT ["./entrypoint.sh"] From b6e2d04bb9ad59c7786a3f10d556e3c64b2d4e02 Mon Sep 17 00:00:00 2001 From: Daniel Genezini Date: Fri, 12 May 2023 20:23:36 -0300 Subject: [PATCH 4/4] Fix output --- linux/preview/examples/mssql-customize/configure-db.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/preview/examples/mssql-customize/configure-db.sh b/linux/preview/examples/mssql-customize/configure-db.sh index b729bef7..e678b630 100644 --- a/linux/preview/examples/mssql-customize/configure-db.sh +++ b/linux/preview/examples/mssql-customize/configure-db.sh @@ -11,7 +11,7 @@ i=0 while [[ $DBSTATUS -ne 0 ]] && [[ $i -lt $TRIES ]]; do i=$((i+1)) - DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P $MSSQL_SA_PASSWORD -Q "SET NOCOUNT ON; Select SUM(state) from sys.databases" > /dev/null 2>&1) || DBSTATUS=1 + DBSTATUS=$(/opt/mssql-tools/bin/sqlcmd -h -1 -t 1 -U sa -P $MSSQL_SA_PASSWORD -Q "SET NOCOUNT ON; Select COALESCE(SUM(state), 0) from sys.databases") || DBSTATUS=1 sleep 1s done