Skip to content

Commit fdb3c8e

Browse files
GRUNENWALD Florianmcmoe
GRUNENWALD Florian
authored andcommitted
Use a ping to wait for mssqlserver or to check its health
1 parent 3348aa3 commit fdb3c8e

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ RUN chmod +x /usr/config/configure-db.sh
1414
ENTRYPOINT ["./entrypoint.sh"]
1515

1616
# Tail the setup logs to trap the process
17-
CMD ["tail -f /var/opt/mssql/log/errorlog*"]
17+
CMD ["tail -f /dev/null"]
1818

19-
HEALTHCHECK --interval=15s CMD grep -q "MSSQL CONFIG COMPLETE" ./config.log
19+
HEALTHCHECK --interval=15s CMD /opt/mssql-tools/bin/sqlcmd -U sa -P $SA_PASSWORD -Q "select 1" && grep -q "MSSQL CONFIG COMPLETE" ./config.log

configure-db.sh

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
#!/bin/bash
22

33
# wait for MSSQL server to start
4-
export STATUS=0
4+
export STATUS=1
55
i=0
6-
while [[ $STATUS -eq 0 ]] || [[ $i -lt 30 ]]; do
7-
sleep 1
6+
7+
while [[ $STATUS -ne 0 ]] && [[ $i -lt 30 ]]; do
88
i=$i+1
9-
STATUS=$(grep 'Recovery is complete' /var/opt/mssql/log/errorlog* | wc -l)
9+
/opt/mssql-tools/bin/sqlcmd -t 1 -U sa -P $SA_PASSWORD -Q "select 1" >> /dev/null
10+
STATUS=$?
1011
done
1112

13+
if [ $STATUS -ne 0 ]; then
14+
echo "Error: MSSQL SERVER took more than thirty seconds to start up."
15+
exit 1
16+
fi
17+
1218
echo "======= MSSQL SERVER STARTED ========" | tee -a ./config.log
1319
# Run the setup script to create the DB and the schema in the DB
1420
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -d master -i setup.sql

0 commit comments

Comments
 (0)