Skip to content

Commit

Permalink
Fix broken Microsoft SQL Database (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
BreadSpoon authored Feb 3, 2020
1 parent f76f019 commit 18eaa1f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 32 deletions.
12 changes: 7 additions & 5 deletions Microsoft SQL Server/db/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
FROM mcr.microsoft.com/mssql/server:2017-latest
LABEL maintainer "BreadSpoon <[email protected]>"

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
RUN sed -i -e "s|@@HOSTNAME@@|${HOSTNAME}|" "/var/opt/mssql/mssql.conf"

CMD /bin/bash ./entrypoint.sh
5 changes: 2 additions & 3 deletions Microsoft SQL Server/db/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 0 additions & 18 deletions Microsoft SQL Server/db/init_server.sh

This file was deleted.

5 changes: 4 additions & 1 deletion Microsoft SQL Server/db/mssql.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 12 additions & 5 deletions Microsoft SQL Server/db/run_sql_statements.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash

declare -r MAXDELAY=20

run_sql() {
local -r CMD="${1}"
shift
Expand All @@ -18,13 +16,22 @@ 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}"
replace_vars "${sf}"
run_sql "${sf}"
done

exit 0
exit 0

0 comments on commit 18eaa1f

Please sign in to comment.