From efcb8a7da97cc6d3b8bf005739d72069df052e64 Mon Sep 17 00:00:00 2001 From: Anders Einar Hilden Date: Mon, 27 Jul 2020 15:38:25 +0000 Subject: [PATCH] entrypoint_nginx.sh: Make it "safe" to run with INIT=true multiple times --- server/files/entrypoint_nginx.sh | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/server/files/entrypoint_nginx.sh b/server/files/entrypoint_nginx.sh index e97602c..46fdda1 100755 --- a/server/files/entrypoint_nginx.sh +++ b/server/files/entrypoint_nginx.sh @@ -73,6 +73,12 @@ init_mysql(){ echo $? } + isDBinitDone () { + # Table attributes has existed since at least v2.1 + echo "DESCRIBE attributes" | $MYSQLCMD 1>/dev/null + echo $? + } + RETRY=100 until [ $(isDBup) -eq 0 ] || [ $RETRY -le 0 ] ; do echo "Waiting for database to come up" @@ -84,7 +90,12 @@ init_mysql(){ exit 1 fi - $MYSQLCMD < /var/www/MISP/INSTALL/MYSQL.sql + if [ $(isDBinitDone) -eq 0 ]; then + echo "Database has already been initialized" + else + echo "Database has not been initialized, importing MySQL scheme..." + $MYSQLCMD < /var/www/MISP/INSTALL/MYSQL.sql + fi } sync_files(){ @@ -104,7 +115,7 @@ done # Things we should do when we have the INITIALIZE Env Flag if [[ "$INIT" == true ]]; then - echo "Import MySQL scheme..." && init_mysql + echo "Setup MySQL..." && init_mysql echo "Setup MISP files dir..." && init_misp_files echo "Ensure SSL certs exist..." && init_ssl fi