+add `make start`/`make stop` with pre/post scripts +implemented database restore & backup
This commit is contained in:
parent
1b5f39285d
commit
ffa11a8b71
|
@ -0,0 +1,15 @@
|
|||
start:
|
||||
@echo -n "> 1. Execute pre-start script..........";
|
||||
@bash ./metactl/pre-start.sh && echo "done" || (echo "failed"; exit 1);
|
||||
@echo -n "> 2. Build & launch environment........";
|
||||
@docker-compose up -d > /dev/null 2>&1 && echo "done" || (echo "failed"; exit 1);
|
||||
@echo -n "> 3. Execute post-start script.........";
|
||||
@bash ./metactl/post-start.sh && echo "done" || (echo "failed"; exit 1);
|
||||
|
||||
stop:
|
||||
@echo -n "> 1. Execute pre-stop script...........";
|
||||
@bash ./metactl/pre-stop.sh && echo "done" || (echo "failed"; exit 1);
|
||||
@echo -n "> 2. Stop and remove environment.....";
|
||||
@docker-compose down > /dev/null 2>&1 && echo "done" || (echo "failed"; exit 1);
|
||||
@echo -n "> 3. Execute post-stop script..........";
|
||||
@bash ./metactl/post-stop.sh && echo "done" || (echo "failed"; exit 1);
|
|
@ -14,6 +14,7 @@ git clone --recursive https://git.xdrm.io/ptut/virtenv.git
|
|||
You need a consistent Linux System with the following packages :
|
||||
- `docker`
|
||||
- `docker-compose`
|
||||
- `make`
|
||||
|
||||
|
||||
You need to add a local dns record in `/etc/hosts`:
|
||||
|
@ -26,12 +27,15 @@ You need to add a local dns record in `/etc/hosts`:
|
|||
|
||||
**Launch the environment**
|
||||
```bash
|
||||
docker-compose up -d
|
||||
make start
|
||||
```
|
||||
- *pre-start* and *post-start* script will be executed (*i.e.* restore database, etc)
|
||||
- the mounted files will match in the `./virtual` folder.
|
||||
- the website will be accessible at 'ptut.com:8080'.
|
||||
|
||||
**Stop the environment**
|
||||
```bash
|
||||
docker-compose down
|
||||
make stop
|
||||
```
|
||||
- *pre-stop* and *post-stop* script will be executed (*i.e.* backup database, etc)
|
||||
- the mounted files will remain in `virtual/` (*e.g.* `/var/log/`).
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 1. Absolute directory
|
||||
ROOT="$(dirname `realpath $0`)";
|
||||
|
||||
# 2. Service container names
|
||||
MARIADB_SERVICE="mariadb";
|
||||
PHPFPM_SERVICE="php-fpm";
|
||||
NGINX_SERVICE="nginx";
|
||||
|
||||
# 3. Mariadb credentials
|
||||
MARIADB_ROOT_PASSWORD="root";
|
||||
MARIADB_DATABASE_NAME="vhost";
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
source $(dirname `realpath $0`)/environment.sh;
|
||||
|
||||
#############################################
|
||||
## ##
|
||||
## Executed after launching containers ##
|
||||
## ##
|
||||
#############################################
|
||||
|
||||
# 1.1. Restore mariadb 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="$?";
|
||||
|
||||
# 1.2. Try until connection OK
|
||||
while [ "$DB_RESTORED" != "0" ]; do
|
||||
sleep 1;
|
||||
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;
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
source $(dirname `realpath $0`)/environment.sh;
|
||||
|
||||
############################################
|
||||
## ##
|
||||
## Executed after stopping containers ##
|
||||
## ##
|
||||
############################################
|
|
@ -0,0 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
source $(dirname `realpath $0`)/environment.sh;
|
||||
|
||||
##############################################
|
||||
## ##
|
||||
## Executed before launching containers ##
|
||||
## ##
|
||||
##############################################
|
|
@ -0,0 +1,12 @@
|
|||
#!/bin/bash
|
||||
|
||||
source $(dirname `realpath $0`)/environment.sh;
|
||||
|
||||
#############################################
|
||||
## ##
|
||||
## Executed before stopping containers ##
|
||||
## ##
|
||||
#############################################
|
||||
|
||||
# 1. Backup mariadb database
|
||||
docker exec $MARIADB_SERVICE mysqldump -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME > $ROOT/persistent/mariadb.sql;
|
Loading…
Reference in New Issue