Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid database corruption on docker stop or docker compose stop #2611

Merged
merged 2 commits into from
May 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 43 additions & 13 deletions install/OS_specific/Docker/init.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash

VERT="\\033[1;32m"
NORMAL="\\033[0;39m"
ROUGE="\\033[1;31m"
Expand All @@ -8,17 +9,34 @@ BLANC="\\033[0;02m"
BLANCLAIR="\\033[1;08m"
JAUNE="\\033[1;33m"
CYAN="\\033[1;36m"


FILE_STOP="/root/stop_requested"

docker_stop(){
echo "${JAUNE}Stopping Jeedom container${NORMAL}"
echo "${VERT}Killing CRON${NORMAL}"
killall cron
echo "${VERT}Stopping Apache gracefully${NORMAL}"
service apache2 stop
echo "${VERT}Stopping Database gracefully${NORMAL}"
service_mariadb stop
echo "${VERT}Stopping ATD gracefully${NORMAL}"
service atd stop
echo "${ROUGE}Requesting stop on init.sh${NORMAL}"
touch ${FILE_STOP}
exit 0
}

service_mariadb(){
service mysql $1
if [ $? -ne 0 ]; then
service mariadb $1
if [ $? -ne 0 ]; then
echo "${ROUGE}Cannot start mariadb - Cancelling${NORMAL}"
return 1
fi
fi
return 0
service mysql $1
if [ $? -ne 0 ]; then
service mariadb $1
if [ $? -ne 0 ]; then
echo "${ROUGE}Cannot start mariadb - Cancelling${NORMAL}"
return 1
fi
fi
return 0
}

echo 'Start init'
Expand All @@ -45,7 +63,7 @@ else
echo "DROP DATABASE IF EXISTS jeedom;" | mysql
echo "CREATE DATABASE jeedom;" | mysql
echo "GRANT ALL PRIVILEGES ON jeedom.* TO 'jeedom'@'localhost';" | mysql
fi
fi

cp ${WEBSERVER_HOME}/core/config/common.config.sample.php ${WEBSERVER_HOME}/core/config/common.config.php
sed -i "s/#PASSWORD#/${DB_PASSWORD}/g" ${WEBSERVER_HOME}/core/config/common.config.php
Expand All @@ -65,7 +83,11 @@ if [ $(which mysqld | wc -l) -ne 0 ]; then
chown -R mysql:mysql /var/lib/mysql /var/run/mysqld
service_mariadb restart
if [ $? -ne 0 ]; then
service_mariadb restart
# That can lead to FATAL corruption of databases
# rm /var/lib/mysql/ib_logfile*
# service_mariadb restart
echo "${ROUGE}Starting Database FAILED${NORMAL}"
exit 1
fi
fi

Expand All @@ -89,4 +111,12 @@ chown -R www-data:www-data ${WEBSERVER_HOME}
echo 'Start apache2'
service apache2 start

cron -f
echo 'Start CRON daemon'
cron

#TAKE CARE : the init.sh script is running under sh so trap only takes signal_number
echo 'Add trap docker_stop'
trap "docker_stop $$ ;" 15

rm "${FILE_STOP}" 1>/dev/null 2>&1
while [ ! -e "${FILE_STOP}" ]; do sleep 1; done
Loading