Compare commits
No commits in common. "master" and "stable" have entirely different histories.
52
Makefile
52
Makefile
|
@ -1,48 +1,32 @@
|
|||
start:
|
||||
@test "`docker-compose ps | wc -l`" -le "2" || (echo -e "/!\\ already running environment\n"; exit 1);
|
||||
@echo -e "\e[33m> [1] pre-start script\e[0m";
|
||||
@bash ./metactl/pre-start.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo "> [1] pre-start script";
|
||||
@bash ./metactl/pre-start.sh && echo "< done" || (echo "< failed"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [2] Build & launch environment\e[0m";
|
||||
@echo "> [2] Build & launch environment";
|
||||
@docker-compose up -d > /dev/null 2>&1 && echo "< done" || (echo "< failed"; exit 1);
|
||||
@echo;
|
||||
@docker-compose up -d && echo -e "\e[33m< done\e[0m" || (echo "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [3] post-start script\e[0m";
|
||||
@bash ./metactl/post-start.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo -e "\e[0m";
|
||||
|
||||
start-no-log:
|
||||
@test "`docker-compose ps | wc -l`" -le "2" || (echo -e "/!\\ already running environment\n"; exit 1);
|
||||
@echo -e "\e[33m> [1] pre-start script\e[0m";
|
||||
@bash ./metactl/pre-start.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [2] Build & launch environment\e[0m";
|
||||
@docker-compose up -d > /dev/null 2>&1 && echo -e "\e[33m< done\e[0m" || (echo "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [3] post-start script\e[0m";
|
||||
@bash ./metactl/post-start.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo -e "\e[0m";
|
||||
@echo "> [3] post-start script";
|
||||
@bash ./metactl/post-start.sh && echo "< done" || (echo "< failed"; exit 1);
|
||||
|
||||
start-no-cache:
|
||||
@test "`docker-compose ps | wc -l`" -le "2" || (echo -e "/!\\ already running environment\n"; exit 1);
|
||||
@echo -e "\e[33m> [1] pre-start script\e[0m";
|
||||
@bash ./metactl/pre-start.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo "> [1] pre-start script";
|
||||
@bash ./metactl/pre-start.sh && echo "< done" || (echo "< failed"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [2] Build & launch environment\e[0m";
|
||||
@echo "> [2] Build & launch environment";
|
||||
@docker-compose up -d --build > /dev/null 2>&1 && echo "< done" || (echo "< failed"; exit 1);
|
||||
@echo;
|
||||
@docker-compose up -d --build && echo -e "\e[33m< done\e[0m" || (echo "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [3] post-start script\e[0m";
|
||||
@bash ./metactl/post-start.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo -e "\e[0m";
|
||||
@echo "> [3] post-start script";
|
||||
@bash ./metactl/post-start.sh && echo "< done" || (echo "< failed"; exit 1);
|
||||
|
||||
stop:
|
||||
@test "`docker-compose ps | wc -l`" -gt "2" || (echo -e "/!\\ no running environment\n"; exit 1);
|
||||
@echo -e "\e[33m> [1] pre-stop script\e[0m";
|
||||
@bash ./metactl/pre-stop.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo "> [1] pre-stop script";
|
||||
@bash ./metactl/pre-stop.sh && echo "< done" || (echo "< failed"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [2] Stop and remove environment\e[0m";
|
||||
@docker-compose down --remove-orphans > /dev/null 2>&1 && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo "> [2] Stop and remove environment";
|
||||
@docker-compose down --remove-orphans > /dev/null 2>&1 && echo "< done" || (echo "< failed"; exit 1);
|
||||
@echo;
|
||||
@echo -e "\e[33m> [3] post-stop script\e[0m";
|
||||
@bash ./metactl/post-stop.sh && echo -e "\e[33m< done\e[0m" || (echo -e "\e[33m< failed\e[0m"; exit 1);
|
||||
@echo "> [3] post-stop script";
|
||||
@bash ./metactl/post-stop.sh && echo "< done" || (echo "< failed"; exit 1);
|
||||
|
|
42
README.md
42
README.md
|
@ -1,15 +1,41 @@
|
|||
# PTUT Virtual Environment
|
||||
|
||||
## Prerequisites
|
||||
|
||||
## Cloning
|
||||
|
||||
In order for the *web* submodule to load, you **must** clone with :
|
||||
|
||||
---
|
||||
## Fast Install
|
||||
|
||||
Launch the following command in your favorite terminal :
|
||||
```bash
|
||||
bash -c "`curl https://xdrm.io/script/ptut-installer`"
|
||||
git clone --recursive https://git.xdrm.io/ptut/virtenv.git
|
||||
```
|
||||
**TODO**
|
||||
[ ] fix unstable `npm` issue for newer versions (vulnerability check)
|
||||
|
||||
## Requirements
|
||||
|
||||
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`:
|
||||
```text
|
||||
127.0.0.1 ptut.com
|
||||
```
|
||||
|
||||
## Commands
|
||||
|
||||
|
||||
**Launch the environment**
|
||||
```bash
|
||||
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 [http://ptut.com:8080](http://ptut.com:8080).
|
||||
|
||||
**Stop the environment**
|
||||
```bash
|
||||
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/`).
|
|
@ -15,7 +15,6 @@ services:
|
|||
expose:
|
||||
- '3306'
|
||||
|
||||
|
||||
php-fpm:
|
||||
build:
|
||||
context: .
|
||||
|
|
|
@ -1,376 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
#*************************#
|
||||
# RELEASER:check #
|
||||
#*************************#
|
||||
# Designed & Developed by #
|
||||
# Adrien Marquès #
|
||||
# <xdrm-brackets> #
|
||||
#*************************#
|
||||
# git.xdrm.io #
|
||||
#*************************#
|
||||
|
||||
S="20"
|
||||
|
||||
inline_progress(){
|
||||
|
||||
# 1. init arguments
|
||||
text=""
|
||||
size="$S"
|
||||
sep=" "
|
||||
|
||||
# 2. extract text
|
||||
test ! -z "$1" && text="$1";
|
||||
|
||||
# 3. extract size
|
||||
test ! -z "$2" && test "`expr $2 + 0 2>/dev/null`" = "$2" && size="$2";
|
||||
|
||||
# 4. Write text
|
||||
len="`echo -n \"$text\" | wc -m`";
|
||||
echo -n "$text";
|
||||
for i in `seq $len $size`; do echo -n "$sep"; done;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# (1) Check if requirements are installed
|
||||
#--------------------------------------------------------#
|
||||
echo -e "\e[33m>\e[0m (1) required programs \e[33m<\e[0m"
|
||||
|
||||
requirements="curl git docker docker-compose make"
|
||||
|
||||
for r in $requirements; do
|
||||
|
||||
inline_progress " . $r";
|
||||
|
||||
if which $r >/dev/null 2>&1; then
|
||||
echo "ok";
|
||||
else
|
||||
echo "missing";
|
||||
echo -e "\n\e[31m/!\\\\\e[0m you must install \e[33m$r\e[0m.";
|
||||
echo -e " this program is required to install the project";
|
||||
exit 1;
|
||||
fi;
|
||||
done;
|
||||
|
||||
|
||||
|
||||
# (2) Check docker permissions
|
||||
#--------------------------------------------------------#
|
||||
echo;
|
||||
echo -e "\e[33m>\e[0m (2) docker \e[33m<\e[0m";
|
||||
|
||||
# (1) docker permissions #
|
||||
inline_progress " . group";
|
||||
if groups | grep 'docker' >/dev/null 2>&1; then
|
||||
echo "ok";
|
||||
else
|
||||
echo "missing";
|
||||
echo;
|
||||
echo -e " you might add the current user to the \e[33mdocker\e[0m group !";
|
||||
echo -e "\e[31m/!\\\\\e[0m it is safer for administrative tasks. You might want";
|
||||
echo -e " to avoid using 'root' for docker.";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
|
||||
|
||||
# (3) find out http installer
|
||||
#--------------------------------------------------------#
|
||||
echo;
|
||||
echo -e "\e[33m>\e[0m (3) http installer \e[33m<\e[0m";
|
||||
inline_progress " * http server";
|
||||
echo;
|
||||
|
||||
# 1. Check for installed candidates
|
||||
existing="apache2 httpd nginx"
|
||||
candidates="";
|
||||
ncandidates="0"
|
||||
|
||||
i="0"
|
||||
for current in $existing; do
|
||||
|
||||
inline_progress " . $current";
|
||||
if which $current >/dev/null 2>&1; then
|
||||
echo "ok";
|
||||
test -z "$candidates" && candidates="$current" || candidates="$candidates $current";
|
||||
ncandidates="`expr $ncandidates + 1`";
|
||||
else
|
||||
echo "..";
|
||||
fi;
|
||||
|
||||
i="`expr $i + 1`";
|
||||
done;
|
||||
|
||||
|
||||
# 2. fail if no candidate
|
||||
if [ "$ncandidates" -lt 1 ]; then
|
||||
echo;
|
||||
echo -e " no http server has been found, you might install one.";
|
||||
echo -e "\e[31m/!\\\\\e[0m the installer supports the most common ones: \e[33mnginx\e[0m"
|
||||
echo -e " and \e[33mapache\e[0m (httpd)";
|
||||
exit 1;
|
||||
|
||||
# 3. only one candidate
|
||||
elif [ "$ncandidates" -eq 1 ]; then
|
||||
echo;
|
||||
echo -e " \e[33m$candidates\e[0m http server has been found. a reverse proxy will be"
|
||||
echo -e "\e[34m(!)\e[0m installed in order for the project to be remotely accessible.";
|
||||
echo -e " do you want to use $candidates ? \e[33my\e[0m/\e[33mn\e[0m";
|
||||
read -p " > " -n1 install; echo;
|
||||
|
||||
case "$install" in
|
||||
Y|y) ;;
|
||||
*) echo -e "\n\e[31m/!\\\\\e[0m aborting installation"; exit 1;;
|
||||
esac;
|
||||
|
||||
http_installer="$candidates";
|
||||
|
||||
# 4. multiple candidates
|
||||
else
|
||||
echo;
|
||||
echo -e " multiple http server candidates have been found. a reverse proxy will be"
|
||||
echo -e "\e[34m(!)\e[0m installed in order for the project to be remotely accessible.";
|
||||
echo -e " please choose the http server one you want to use:"
|
||||
echo -e " (0) \e[33mabort\e[0m"
|
||||
i="1";
|
||||
for c in $candidates; do echo -e " ($i) \e[33m$c\e[0m"; i="`expr $i + 1`"; done;
|
||||
read -p " > " -n1 install; echo;
|
||||
|
||||
# 4.1. Abort (or invalid)
|
||||
if [ "`expr $install + 0 2>/dev/null`" != "$install" -o "$install" = "0" ]; then
|
||||
echo -e "\n\e[31m/!\\\\\e[0m aborting installation"; exit 1;
|
||||
elif [ "$install" -gt "$ncandidates" ]; then
|
||||
echo -e "\n\e[31m/!\\\\\e[0m aborting installation"; exit 1;
|
||||
fi;
|
||||
|
||||
http_installer=$(echo $candidates | awk "{print \$$install}")
|
||||
fi;
|
||||
echo;
|
||||
|
||||
# 5. 'httpd' is service name, but config dir is apache2
|
||||
http_root="/etc/$http_installer";
|
||||
test "$http_installer" = "httpd" && http_root="/etc/apache2";
|
||||
|
||||
# 6. configuration root dir
|
||||
inline_progress " . config root";
|
||||
|
||||
if [ -d "$http_root" ]; then
|
||||
echo "ok";
|
||||
else
|
||||
echo "missing";
|
||||
echo -e "\n\e[31m/!\\\\\e[0m cannot find configuration folder \e[33m$http_root\e[0m. aborting installation";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# 7. configuration structure
|
||||
inline_progress " . config tree";
|
||||
|
||||
if [ -d "$http_root/sites-available" -a -d "$http_root/sites-enabled" ]; then
|
||||
echo "ok";
|
||||
else
|
||||
echo "invalid";
|
||||
echo -e "\n invalid configuration structure. You might have \e[33m$http_root/sites-available\e[0m containing";
|
||||
echo -e "\e[31m/!\\\\\e[0m your configurations and \e[33m$http_root/sites-enabled\e[0m containing symbolic links";
|
||||
echo -e " only for activated configurations. aborting installation";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
|
||||
# (4) information disclaimer
|
||||
#--------------------------------------------------------#
|
||||
echo;
|
||||
echo -e "\e[33m>\e[0m (4) information \e[33m<\e[0m";
|
||||
echo;
|
||||
echo -e " \e[34m(!)\e[0m (1) the project will run inside docker containers (3 containers).";
|
||||
echo;
|
||||
echo -e " \e[34m(!)\e[0m (2) the only links it has with the host machine (this machine) are:";
|
||||
echo;
|
||||
echo -e " \e[34m(!)\e[0m - \e[34mweb files\e[0m (that will be shared between multiple containers)";
|
||||
echo -e " \e[34m(!)\e[0m - \e[34menvironment files\e[0m (for continuous integration)";
|
||||
echo -e " \e[34m(!)\e[0m - \e[34ma listening socket\e[0m (to accept incoming http requests)";
|
||||
echo;
|
||||
echo -e " \e[34m(!)\e[0m (3) in order for incoming requests to follow the path:";
|
||||
echo -e " \e[34m(!)\e[0m [remote] => [http server] => [docker]";
|
||||
echo;
|
||||
echo -e " \e[34m(!)\e[0m we will install a reverse proxy on the http server ($http_installer) to";
|
||||
echo -e " \e[34m(!)\e[0m automatically redirect requests from a specific \e[34m<HOST>\e[0m to docker's";
|
||||
echo -e " \e[34m(!)\e[0m listening \e[34m<PORT>\e[0m.";
|
||||
echo;
|
||||
echo -e " \e[34m(!)\e[0m WARNING: The \e[34m<HOST>\e[0m must be available for your server and be a sub-domain";
|
||||
echo -e " \e[34m(!)\e[0m in order for your DNS to be valid.";
|
||||
echo;
|
||||
echo -e " \e[34m(!)\e[0m EXAMPLE: If your server has \e[33mexample.net\e[0m as a DNS.";
|
||||
echo -e " \e[34m(!)\e[0m the \e[34m<HOST>\e[0m \e[33mtest.example.net\e[0m is valid";
|
||||
echo -e " \e[34m(!)\e[0m the \e[34m<HOST>\e[0m \e[33mtest.google.com\e[0m is not valid";
|
||||
|
||||
|
||||
|
||||
# (5) prompt server variables
|
||||
#--------------------------------------------------------#
|
||||
echo;
|
||||
echo -e "\e[33m>\e[0m (5) redirection variables \e[33m<\e[0m";
|
||||
|
||||
# 1. Port
|
||||
minport="1024"
|
||||
maxport="49151"
|
||||
echo -e " * what port do you want docker to use ? (between $minport and $maxport)";
|
||||
echo -e " ( values other than \e[33m8080\e[0m may be unstable )";
|
||||
echo -en " \e[34m<PORT>\e[0m = ";
|
||||
read port;
|
||||
|
||||
if [ -z "$port" -o "`expr $port + 0 2>/dev/null`" != "$port" ]; then
|
||||
echo;
|
||||
echo -e "\e[31m/!\\\\\e[0m invalid port number. aborting installation"
|
||||
exit 1;
|
||||
elif [ "$port" -lt $minport -o "$port" -gt $maxport ]; then
|
||||
echo;
|
||||
echo -e "\e[31m/!\\\\\e[0m port out of range. aborting installation"
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# 2. Host
|
||||
echo -e " * what host do you want to redirect to docker ?";
|
||||
echo -en " \e[34m<HOST>\e[0m = ";
|
||||
read host;
|
||||
|
||||
if [ -z "$host" ]; then
|
||||
echo;
|
||||
echo -e "\e[31m/!\\\\\e[0m invalid host. aborting installation"
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# 3. Unlock permissions
|
||||
echo -n " * sudo access ";
|
||||
if sudo echo "granted"; then
|
||||
echo -n "";
|
||||
else
|
||||
echo;
|
||||
echo -e "\e[31m/!\\\\\e[0m permission issue. you must launch the installer with a sudoer. aborting installation"
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# (6) pre-install: reverse-proxy
|
||||
#--------------------------------------------------------#
|
||||
echo;
|
||||
echo -e "\e[33m>\e[0m (6) reverse proxy \e[33m<\e[0m";
|
||||
|
||||
# (1) LOCAL DNS #
|
||||
inline_progress " . local dns";
|
||||
|
||||
# 1.1. remove previously generated + append new line
|
||||
cat /etc/hosts | grep -vP "# generated by: ptut installer" > /tmp/installer_hosts;
|
||||
echo -e "127.0.0.1\t$host\t# generated by: ptut installer" | sudo tee -a /tmp/installer_hosts >/dev/null;
|
||||
|
||||
sudo cp /etc/hosts /etc/hosts.backup;
|
||||
sudo mv /tmp/installer_hosts /etc/hosts;
|
||||
c2="$?";
|
||||
|
||||
# 1.2. manage errors
|
||||
if [ "$c2" = "0" ]; then
|
||||
echo "ok";
|
||||
else
|
||||
echo;
|
||||
echo -e "\e[31m/!\\\\\e[0m cannot write to /etc/hosts. skipping this step."
|
||||
fi;
|
||||
|
||||
|
||||
inline_progress " * $http_installer"; echo;
|
||||
|
||||
# 1. Copy configuration
|
||||
echo -n " - create proxy configuration ";
|
||||
if [ "$http_installer" = "apache2" -o "$http_installer" = "httpd" ]; then
|
||||
echo """<VirtualHost *:80>
|
||||
ServerName $host
|
||||
ServerAlias www.$host
|
||||
|
||||
ProxyPreserveHost On
|
||||
ProxyRequests off
|
||||
ProxyPass / http://127.0.0.1:$port/
|
||||
ProxyPassReverse / http://127.0.0.1:$port/
|
||||
</VirtualHost>""" | sudo tee $http_root/sites-available/$host.reverse-proxy > /dev/null;
|
||||
|
||||
elif [ "$http_installer" = "nginx" ]; then
|
||||
echo """server {
|
||||
listen 80;
|
||||
server_name $host www.$host;
|
||||
|
||||
location / {
|
||||
proxy_set_header Host \$host;
|
||||
proxy_pass http://127.0.0.1:$port;
|
||||
}
|
||||
}""" | sudo tee $http_root/sites-available/$host.reverse-proxy > /dev/null;
|
||||
else
|
||||
echo "error";
|
||||
echo -e "\n\e[31m/!\\\\\e[0m no installer matches '$http_installer'. aborting installation";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# manage error
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "ok";
|
||||
else
|
||||
echo "error";
|
||||
echo -e "\n\e[31m/!\\\\\e[0m cannot write to $http_root/sites-availables/. aborting installation";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
echo -n " - enable proxy ";
|
||||
sudo ln -fs ../sites-available/$host.reverse-proxy $http_root/sites-enabled/$host.reverse-proxy;
|
||||
echo "ok";
|
||||
|
||||
echo -n " - reload server ";
|
||||
sudo systemctl is-active $http_installer || sudo systemctl start $http_installer;
|
||||
sudo systemctl reload $http_installer;
|
||||
echo "ok";
|
||||
|
||||
|
||||
|
||||
# (7) clone sources
|
||||
#--------------------------------------------------------#
|
||||
echo;
|
||||
echo -e "\e[33m>\e[0m (7) fetching \e[33m<\e[0m";
|
||||
|
||||
# 1. Clone
|
||||
inline_progress " . cloning";
|
||||
git clone --recursive https://git.xdrm.io/ptut/virtenv.git $host;
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "ok";
|
||||
else
|
||||
echo "error";
|
||||
echo -e "\n\e[31m/!\\\\\e[0m cannot clone sources to ./$host. aborting installation";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# 2. Fetch database
|
||||
inline_progress " . fetch data";
|
||||
mkdir -p ./$host/metactl/persistent \
|
||||
&& curl https://xdrm.io/script/ptut-database > ./$host/metactl/persistent/mariadb.sql;
|
||||
|
||||
if [ "$?" = "0" ]; then
|
||||
echo "ok";
|
||||
else
|
||||
echo "error";
|
||||
echo -e "\n\e[31m/!\\\\\e[0m cannot fetch data. aborting installation";
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
# 3. Set custom port
|
||||
inline_progress " . port $port";
|
||||
cat ./$host/docker-compose.yml | sed "s/8080:80/$port:80/" > /tmp/docker-compose-new-port;
|
||||
mv /tmp/docker-compose-new-port ./$host/docker-compose.yml;
|
||||
echo "ok";
|
||||
|
||||
# (8) make installer
|
||||
#--------------------------------------------------------#
|
||||
echo;
|
||||
echo -e "\e[33m>\e[0m (8) installer \e[33m<\e[0m";
|
||||
make -C ./$host start;
|
||||
|
||||
|
|
@ -21,11 +21,10 @@ while true; do
|
|||
|
||||
|
||||
# 1. Go to root directory
|
||||
cd $ROOT/../../virtual/vhost;
|
||||
cd $ROOT/../..;
|
||||
|
||||
# 2. Update submodule 'vhost'
|
||||
git checkout master;
|
||||
git pull origin master;
|
||||
git submodule update --remote;
|
||||
|
||||
# 3. Update composer
|
||||
docker exec php-fpm bash -c "cd /vhost; composer install";
|
||||
|
|
|
@ -17,13 +17,11 @@ echo -ne " * mariadb socket..";
|
|||
docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
|
||||
DB_RESTORED="$?";
|
||||
|
||||
sleep 5s;
|
||||
|
||||
# Try until connection OK
|
||||
while [ "$DB_RESTORED" == "1" ]; do
|
||||
while [ "$DB_RESTORED" != "0" ]; do
|
||||
sleep .5;
|
||||
echo -ne ".";
|
||||
timeout 1 docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
|
||||
docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
|
||||
DB_RESTORED="$?";
|
||||
done;
|
||||
|
||||
|
@ -48,17 +46,15 @@ if [ "$DUMP_FILE_EXISTS" = "0" ]; then
|
|||
|
||||
# Restore mariadb database
|
||||
echo -ne " * Restore database..........";
|
||||
cat $MARIADB_DUMP | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null && echo "restored" || echo "failed";
|
||||
cat $MARIADB_DUMP | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME 2>/dev/null && echo "restored" || echo "failed";
|
||||
|
||||
else
|
||||
|
||||
echo "missing";
|
||||
|
||||
echo -ne " * Create trigger............";
|
||||
test ! -d ./virtual/ci && mkdir ./virtual/ci;
|
||||
ec @echo -n "*** Create trigger.............";
|
||||
@test ! -d ./virtual/ci && mkdir ./virtual/ci; (exit 0);
|
||||
|
||||
# Create 'persistent' directory if missing
|
||||
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent && echo "created" || ( echo "error"; exit 1 );
|
||||
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
||||
|
||||
echo " * Create dump file..........created";
|
||||
touch $MARIADB_DUMP;
|
||||
|
@ -83,39 +79,4 @@ docker exec php-fpm bash -c "cd /vhost; composer install" >/dev/null 2>&1 && ech
|
|||
|
||||
# 2. Re-build js/scss
|
||||
echo -n " * Webpack build.............";
|
||||
docker exec php-fpm bash -c "cd /vhost; npm install; npm update; npm run build" >/dev/null 2>&1 && echo "built" || (echo "failed"; exit 1);
|
||||
|
||||
# 3. touch the file the backup loop will use to run
|
||||
echo -n " * Mariadb backup loop.......";
|
||||
|
||||
backup(){
|
||||
if [ ! -d $ROOT/backups ]; then
|
||||
mkdir $ROOT/backups;
|
||||
fi
|
||||
|
||||
touch $ROOT/backuploop
|
||||
while [ -f $ROOT/backuploop ]; do
|
||||
# sleep 24 hours before next backup kick in
|
||||
sleep 86400;
|
||||
docker exec $MARIADB_SERVICE mysqldump --all-databases --flush-privileges -uroot -p$MARIADB_ROOT_PASSWORD | gzip > $ROOT/backups/$(date -d "today" +"%Y%m%d%H%M").sql.gz;
|
||||
done;
|
||||
}
|
||||
|
||||
backup &
|
||||
echo "done"
|
||||
|
||||
|
||||
|
||||
## [5] Setup/Fix permissions (for API download)
|
||||
|
||||
# 1. Create download directories
|
||||
echo -n " * Create download folders...";
|
||||
docker exec php-fpm bash -c "mkdir -p /vhost/tmp";
|
||||
docker exec php-fpm bash -c "mkdir -p /vhost/public_html/tmp";
|
||||
echo "created"
|
||||
|
||||
# 2. Fix permissions
|
||||
echo -n " * Setup permissions.........";
|
||||
docker exec php-fpm bash -c "chown -R www-data:www-data /vhost";
|
||||
docker exec php-fpm bash -c "chmod -R 775 /vhost";
|
||||
echo "set"
|
||||
docker exec php-fpm bash -c "cd /vhost; npm install; npm run build" >/dev/null 2>&1 && echo "built" || (echo "failed"; exit 1);
|
|
@ -26,7 +26,4 @@ if [ -f $PID_FILE ]; then
|
|||
else
|
||||
echo "already";
|
||||
fi;
|
||||
rm $PID_FILE >/dev/null 2>&1;
|
||||
|
||||
echo -ne " * Kill backup loop..........";
|
||||
rm $ROOT/backuploop 2>/dev/null && echo "killed" || (echo "fail"; exit 1);
|
||||
rm $PID_FILE >/dev/null 2>&1;
|
|
@ -15,5 +15,5 @@ test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
|
|||
|
||||
# 2. Backup database
|
||||
echo -ne " * Backup database...........";
|
||||
docker exec $MARIADB_SERVICE mysqldump --all-databases --flush-privileges -uroot -p$MARIADB_ROOT_PASSWORD > $MARIADB_DUMP;
|
||||
docker exec $MARIADB_SERVICE mysqldump -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME > $MARIADB_DUMP;
|
||||
test "$?" = "0" && echo "done" || (echo "failed"; exit 1);
|
|
@ -1 +1 @@
|
|||
Subproject commit 177752fdc41e8c0326fb328a37e0e113559a3681
|
||||
Subproject commit 6669ff7d8befe936f5773f9ead5a08b3a5e70a6d
|
Loading…
Reference in New Issue