From 18eaa1f3702317879eb36dbea1782f00d0ab3e5f Mon Sep 17 00:00:00 2001 From: BreadSpoon <58331655+BreadSpoon@users.noreply.github.com> Date: Mon, 3 Feb 2020 20:51:40 +0100 Subject: [PATCH] Fix broken Microsoft SQL Database (#33) --- Microsoft SQL Server/db/Dockerfile | 12 +++++++----- Microsoft SQL Server/db/entrypoint.sh | 5 ++--- Microsoft SQL Server/db/init_server.sh | 18 ------------------ Microsoft SQL Server/db/mssql.conf | 5 ++++- Microsoft SQL Server/db/run_sql_statements.sh | 17 ++++++++++++----- 5 files changed, 25 insertions(+), 32 deletions(-) delete mode 100644 Microsoft SQL Server/db/init_server.sh diff --git a/Microsoft SQL Server/db/Dockerfile b/Microsoft SQL Server/db/Dockerfile index 3b1af34..1c5035f 100644 --- a/Microsoft SQL Server/db/Dockerfile +++ b/Microsoft SQL Server/db/Dockerfile @@ -1,15 +1,17 @@ FROM mcr.microsoft.com/mssql/server:2017-latest LABEL maintainer "BreadSpoon " -ENV MSSQL_DATA_DIR /data/mssql-data -ENV MSSQL_LOG_DIR /data/mssql-data -ENV MSSQL_DUMP_DIR /data/mssql-data +ENV MSSQL_MASTER_DATA_FILE /data/mssql-data/master.mdf +ENV MSSQL_MASTER_LOG_FILE /data/mssql-data/mastlog.ldf COPY ./*.sh / COPY ./*.sql / -COPY ./mssql.conf /tmp/mssql.conf +COPY ./mssql.conf /var/opt/mssql/mssql.conf +COPY ./mssql.conf /data/mssql-data/mssql.conf RUN set -ex \ && chmod +x /*.sh -CMD /bin/bash /entrypoint.sh \ No newline at end of file +RUN sed -i -e "s|@@HOSTNAME@@|${HOSTNAME}|" "/var/opt/mssql/mssql.conf" + +CMD /bin/bash ./entrypoint.sh \ No newline at end of file diff --git a/Microsoft SQL Server/db/entrypoint.sh b/Microsoft SQL Server/db/entrypoint.sh index 00f4cc1..6d5cdba 100644 --- a/Microsoft SQL Server/db/entrypoint.sh +++ b/Microsoft SQL Server/db/entrypoint.sh @@ -1,6 +1,5 @@ #!/usr/bin/env bash -/init_server.sh \ - && env \ +env \ && (nohup /run_sql_statements.sh &) \ - && /opt/mssql/bin/sqlservr + && /opt/mssql/bin/sqlservr \ No newline at end of file diff --git a/Microsoft SQL Server/db/init_server.sh b/Microsoft SQL Server/db/init_server.sh deleted file mode 100644 index c2d1cb7..0000000 --- a/Microsoft SQL Server/db/init_server.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -replace_vars() { - local -r DSTFILE="${1}" - shift - - sed -i -e "s|@@HOSTNAME@@|${HOSTNAME}|" \ - "${DSTFILE}" -} - -echo "[*] Pre customizing sql server" - -cp -v /tmp/mssql.conf /var/opt/mssql/mssql.conf -replace_vars /var/opt/mssql/mssql.conf - -echo "[*] Pre customizing sql server done" - -exit 0 diff --git a/Microsoft SQL Server/db/mssql.conf b/Microsoft SQL Server/db/mssql.conf index 6a3f262..111f815 100644 --- a/Microsoft SQL Server/db/mssql.conf +++ b/Microsoft SQL Server/db/mssql.conf @@ -23,7 +23,10 @@ rpcport = 135 memorylimitmb = 4096 [filelocation] -defaultbackupdir = /backup +defaultbackupdir = /data/mssql-data/ +defaultdatadir = /data/mssql-data/ +defaultdumpdir = /data/mssql-data/ +defaultlogdir = /data/mssql-data/ [traceflag] ; Allows a table variable to trigger recompile when enough number of rows are changed. diff --git a/Microsoft SQL Server/db/run_sql_statements.sh b/Microsoft SQL Server/db/run_sql_statements.sh index ac4d0ec..b584d78 100644 --- a/Microsoft SQL Server/db/run_sql_statements.sh +++ b/Microsoft SQL Server/db/run_sql_statements.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -declare -r MAXDELAY=20 - run_sql() { local -r CMD="${1}" shift @@ -18,8 +16,17 @@ replace_vars() { "${DSTFILE}" } -echo "[*] Start executing sql scripts in ${MAXDELAY} seconds." -sleep ${MAXDELAY} +echo "Wait for server to startup" +while [ ! -f /var/opt/mssql/log/errorlog ] +do + sleep 2 +done + +tail -f /var/opt/mssql/log/errorlog | while read LOGLINE +do + [[ "${LOGLINE}" == *"Using 'xpstar.dll' version"* ]] && pkill -P $$ tail +done +echo "[*] Start executing sql scripts." for sf in $(ls -v /*.sql); do echo "Execute ${sf}" @@ -27,4 +34,4 @@ for sf in $(ls -v /*.sql); do run_sql "${sf}" done -exit 0 +exit 0 \ No newline at end of file