ptut-virtenv/metactl/post-start.sh

51 lines
1.2 KiB
Bash

#!/bin/bash
source $(dirname `realpath $0`)/environment.sh;
#############################################
## ##
## Executed after launching containers ##
## ##
#############################################
## [1] Restore database
# 1. Check if dump file exists
echo -ne " * Check dump file...........";
test -f $ROOT/persistent/mariadb.sql;
DUMP_FILE_EXISTS="$?";
# 2. Restore database
if [ "$DUMP_FILE_EXISTS" = "0" ]; then
echo "found";
# Restore mariadb database
echo -ne " * Restore database";
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
DB_RESTORED="$?";
# Try until connection OK
while [ "$DB_RESTORED" != "0" ]; do
sleep .5;
echo -ne ".";
cat $ROOT/persistent/mariadb.sql | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null;
DB_RESTORED="$?";
done;
echo "restored";
else
echo "missing";
# Create 'persistent' directory if missing
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
echo " * Create dump file..........created";
touch $ROOT/persistent/mariadb.sql;
fi;