2018-02-18 14:28:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
source $(dirname `realpath $0`)/environment.sh;
|
|
|
|
|
|
|
|
#############################################
|
|
|
|
## ##
|
|
|
|
## Executed after launching containers ##
|
|
|
|
## ##
|
|
|
|
#############################################
|
|
|
|
|
|
|
|
|
2018-02-18 18:07:44 +00:00
|
|
|
|
2018-02-18 18:17:18 +00:00
|
|
|
## [1] Wait for database to be READY
|
|
|
|
|
|
|
|
# Restore mariadb database
|
|
|
|
echo -ne " * mariadb socket..";
|
|
|
|
docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
|
|
|
|
DB_RESTORED="$?";
|
|
|
|
|
|
|
|
# Try until connection OK
|
|
|
|
while [ "$DB_RESTORED" != "0" ]; do
|
|
|
|
sleep .5;
|
|
|
|
echo -ne ".";
|
|
|
|
docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
|
|
|
|
DB_RESTORED="$?";
|
|
|
|
done;
|
|
|
|
|
|
|
|
echo "ready";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-02-19 21:02:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
## [2] Restore database
|
2018-02-18 18:07:44 +00:00
|
|
|
|
|
|
|
# 1. Check if dump file exists
|
|
|
|
echo -ne " * Check dump file...........";
|
2018-02-18 18:17:18 +00:00
|
|
|
test -f $MARIADB_DUMP;
|
2018-02-18 18:07:44 +00:00
|
|
|
DUMP_FILE_EXISTS="$?";
|
|
|
|
|
|
|
|
# 2. Restore database
|
|
|
|
if [ "$DUMP_FILE_EXISTS" = "0" ]; then
|
|
|
|
|
|
|
|
echo "found";
|
|
|
|
|
|
|
|
# Restore mariadb database
|
2018-02-18 18:17:18 +00:00
|
|
|
echo -ne " * Restore database..........";
|
|
|
|
cat $MARIADB_DUMP | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null && echo "restored" || echo "failed";
|
2018-02-18 18:07:44 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
|
2018-02-19 20:33:19 +00:00
|
|
|
ec @echo -n "*** Create trigger.............";
|
|
|
|
@test ! -d ./virtual/ci && mkdir ./virtual/ci; (exit 0);
|
2018-02-18 18:07:44 +00:00
|
|
|
|
|
|
|
# Create 'persistent' directory if missing
|
|
|
|
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
|
|
|
|
|
|
|
echo " * Create dump file..........created";
|
2018-02-18 18:17:18 +00:00
|
|
|
touch $MARIADB_DUMP;
|
2018-02-18 18:07:44 +00:00
|
|
|
|
|
|
|
|
2018-02-19 21:02:07 +00:00
|
|
|
fi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## [3] Grant www-data for CI triggers
|
|
|
|
echo -n " * Grant php on triggers.....";
|
|
|
|
docker exec php-fpm chown www-data -R /ci && echo "granted" || (echo "failed"; exit 1);
|