Compare commits

...

48 Commits

Author SHA1 Message Date
Adrien Marquès 0c24af0379 minmod 2018-06-13 12:00:36 +02:00
Adrien Marquès e30539584e update readme 2018-06-13 11:55:23 +02:00
Adrien Marquès 40a2a3fb23 fix wrong sentence 2018-06-13 11:28:21 +02:00
Adrien Marquès 623a490879 minmod 2018-06-11 16:50:31 +02:00
Adrien Marquès 8d66a80ddb min color fix 2018-06-11 16:47:29 +02:00
Adrien Marquès 2935bf6aa6 fix 'httpd' directory that is the same as 'apache2' 2018-06-11 16:46:06 +02:00
Adrien Marquès 156df26412 update info icons for http server autoselect/choice 2018-06-11 16:19:50 +02:00
Adrien Marquès bdb704897f [installer] feature to use custom port 2018-06-10 18:26:05 +02:00
Adrien Marquès 9c829c3d82 remove useless installer reliques 2018-06-10 18:22:44 +02:00
Adrien Marquès 657724d58d update README 2018-06-10 18:21:10 +02:00
Adrien Marquès bf01157cd9 all-bundled [rf1] installer 2018-06-10 18:10:24 +02:00
Adrien Marquès 683ef84ab3 installer [rf1] 2018-06-10 17:16:08 +02:00
Adrien Marquès dab26c9ca4 update vhost 2018-06-09 15:26:31 +02:00
Adrien Marquès 519ff5dd1a min update 2018-06-09 15:17:44 +02:00
Adrien Marquès 599933a5ca update vhost 2018-06-09 15:08:58 +02:00
Adrien Marquès 761755fe8e fix PreserveHost 2018-06-09 15:07:11 +02:00
Adrien Marquès 1d1c3c6872 update vhost 2018-06-09 14:58:20 +02:00
Adrien Marquès 1b190288e7 update vhost 2018-06-09 14:35:11 +02:00
Adrien Marquès 60b1da1cd9 fix one-liner for easy-install 2018-06-09 12:37:14 +02:00
Adrien Marquès 4b293a3414 Merge branch 'master' of https://git.xdrm.io/ptut/virtenv 2018-06-09 12:25:30 +02:00
Adrien Marquès 8ad679689b post-start script add API download permission fix 2018-06-09 12:25:25 +02:00
Adrien Marquès 84fa5ca830 add install scripts 2018-06-09 11:54:52 +02:00
Adrien Marquès e072e8ac94 remove debug mariadb port exposure 2018-06-08 05:37:30 -04:00
Adrien Marquès e2a98a849e todo 2018-06-07 08:04:43 -04:00
xdrm-brackets 6b07e56996 fix bash-non-compatible ';' after '&' bg 2018-05-14 12:11:49 +02:00
Mascaro Lucas 76712a2378 Implemented automatic backup of mariadb (every 24 hours) 2018-05-14 01:47:20 +02:00
SeekDaSky 769d5ed9ba fix sql backup not working 2018-04-04 09:37:35 +02:00
xdrm-brackets e2ff51accd ~upd 'vhost' submodule 2018-03-25 16:01:22 +02:00
xdrm-brackets d961b46a4e ~upd 'vhost' submodule 2018-03-22 11:08:25 +01:00
xdrm-brackets 385f0dd97c [metactl.post-start] database socket timeout from 0.1 to 1 2018-03-21 01:18:44 +01:00
xdrm-brackets 728f4f3e71 [metactl.post-start] restore without specifying database [metactl.pre-stop] backup with --flush-privileges 2018-03-21 00:11:11 +01:00
xdrm-brackets 8b3466249c ~upd 'vhost' submodule 2018-03-18 17:36:49 +01:00
xdrm-brackets dc14173fcb [post-start.script] now works with timeout for testing mariadb.socket 2018-03-15 13:36:24 +01:00
xdrm-brackets 0c60cf6d46 [Makefile] fix 2018-03-15 12:27:34 +01:00
xdrm-brackets ecbde7f7db [Makefile] make titles bold to delimit 'docker-compose' output 2018-03-15 12:23:11 +01:00
xdrm-brackets 33e6992be8 [Makefile] 'make start' logs output by default 'make start-no-log' don't 2018-03-15 12:11:06 +01:00
xdrm-brackets d280118b9b [README] updated 'fast-install' method 2018-03-14 22:47:58 +01:00
xdrm-brackets f60a35216e minfix 2018-03-14 22:15:24 +01:00
SeekDaSky 116ded48c3 backup all databases instead of just vhost 2018-03-11 16:38:28 +01:00
xdrm-brackets b8b5f6c7ac Merge branch 'master' of gogs:ptut/virtenv 2018-03-04 12:03:23 +01:00
xdrm-brackets c982a601a0 updated 'vhost' 2018-03-04 12:03:12 +01:00
xdrm-brackets d12434fcb1 [repo.professor] remove PDO exception mode 2018-03-04 12:02:33 +01:00
xdrm-brackets dac44ed391 updated 'vhost' + make CI web really update vhost on branch master 2018-03-03 22:33:06 +01:00
xdrm-brackets bebea1e76e ~upd 'vhost' submodule 2018-03-03 22:28:00 +01:00
xdrm-brackets 7b0b15829e ~upd 'vhost' submodule 2018-02-27 14:36:49 +01:00
xdrm-brackets 7c1b7de905 ~upd 'vhost' submodule 2018-02-20 21:36:14 +01:00
xdrm-brackets 281ca55a5d ~upd 'vhost' submodule 2018-02-20 21:33:03 +01:00
xdrm-brackets 26f45a1c05 ~upd 'vhost' submodule 2018-02-20 19:00:42 +01:00
11 changed files with 474 additions and 64 deletions

View File

@ -1,32 +1,48 @@
start:
@test "`docker-compose ps | wc -l`" -le "2" || (echo -e "/!\\ already running environment\n"; exit 1);
@echo "> [1] pre-start script";
@bash ./metactl/pre-start.sh && echo "< done" || (echo "< failed"; 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 "> [2] Build & launch environment";
@docker-compose up -d > /dev/null 2>&1 && echo "< done" || (echo "< failed"; exit 1);
@echo -e "\e[33m> [2] Build & launch environment\e[0m";
@echo;
@echo "> [3] post-start script";
@bash ./metactl/post-start.sh && echo "< done" || (echo "< failed"; exit 1);
@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";
start-no-cache:
@test "`docker-compose ps | wc -l`" -le "2" || (echo -e "/!\\ already running environment\n"; exit 1);
@echo "> [1] pre-start script";
@bash ./metactl/pre-start.sh && echo "< done" || (echo "< failed"; 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 "> [2] Build & launch environment";
@docker-compose up -d --build > /dev/null 2>&1 && echo "< done" || (echo "< failed"; exit 1);
@echo -e "\e[33m> [2] Build & launch environment\e[0m";
@echo;
@echo "> [3] post-start script";
@bash ./metactl/post-start.sh && echo "< done" || (echo "< failed"; exit 1);
@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";
stop:
@test "`docker-compose ps | wc -l`" -gt "2" || (echo -e "/!\\ no running environment\n"; exit 1);
@echo "> [1] pre-stop script";
@bash ./metactl/pre-stop.sh && echo "< done" || (echo "< failed"; 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;
@echo "> [2] Stop and remove environment";
@docker-compose down --remove-orphans > /dev/null 2>&1 && echo "< done" || (echo "< failed"; exit 1);
@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;
@echo "> [3] post-stop script";
@bash ./metactl/post-stop.sh && echo "< done" || (echo "< failed"; exit 1);
@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);

View File

@ -1,41 +1,15 @@
# 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
git clone --recursive https://git.xdrm.io/ptut/virtenv.git
bash -c "`curl https://xdrm.io/script/ptut-installer`"
```
## 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/`).
**TODO**
[ ] fix unstable `npm` issue for newer versions (vulnerability check)

View File

@ -15,6 +15,7 @@ services:
expose:
- '3306'
php-fpm:
build:
context: .

376
install-scripts/installer Normal file
View File

@ -0,0 +1,376 @@
#!/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;

0
metactl/ci/env Normal file
View File

0
metactl/ci/web Normal file
View File

View File

@ -21,10 +21,11 @@ while true; do
# 1. Go to root directory
cd $ROOT/../..;
cd $ROOT/../../virtual/vhost;
# 2. Update submodule 'vhost'
git submodule update --remote;
git checkout master;
git pull origin master;
# 3. Update composer
docker exec php-fpm bash -c "cd /vhost; composer install";

View File

@ -17,11 +17,13 @@ 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" != "0" ]; do
while [ "$DB_RESTORED" == "1" ]; do
sleep .5;
echo -ne ".";
docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
timeout 1 docker exec $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null;
DB_RESTORED="$?";
done;
@ -46,15 +48,17 @@ 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 $MARIADB_DATABASE_NAME 2>/dev/null && echo "restored" || echo "failed";
cat $MARIADB_DUMP | docker exec -i $MARIADB_SERVICE mysql -uroot -p$MARIADB_ROOT_PASSWORD 2>/dev/null && echo "restored" || echo "failed";
else
ec @echo -n "*** Create trigger.............";
@test ! -d ./virtual/ci && mkdir ./virtual/ci; (exit 0);
echo "missing";
echo -ne " * Create trigger............";
test ! -d ./virtual/ci && mkdir ./virtual/ci;
# Create 'persistent' directory if missing
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent && echo "created" || ( echo "error"; exit 1 );
echo " * Create dump file..........created";
touch $MARIADB_DUMP;
@ -79,4 +83,39 @@ 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 run build" >/dev/null 2>&1 && echo "built" || (echo "failed"; exit 1);
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"

View File

@ -26,4 +26,7 @@ if [ -f $PID_FILE ]; then
else
echo "already";
fi;
rm $PID_FILE >/dev/null 2>&1;
rm $PID_FILE >/dev/null 2>&1;
echo -ne " * Kill backup loop..........";
rm $ROOT/backuploop 2>/dev/null && echo "killed" || (echo "fail"; exit 1);

View File

@ -15,5 +15,5 @@ test ! -d $ROOT/persistent && mkdir -p $ROOT/persistent;
# 2. Backup database
echo -ne " * Backup database...........";
docker exec $MARIADB_SERVICE mysqldump -uroot -p$MARIADB_ROOT_PASSWORD $MARIADB_DATABASE_NAME > $MARIADB_DUMP;
docker exec $MARIADB_SERVICE mysqldump --all-databases --flush-privileges -uroot -p$MARIADB_ROOT_PASSWORD > $MARIADB_DUMP;
test "$?" = "0" && echo "done" || (echo "failed"; exit 1);

@ -1 +1 @@
Subproject commit 6669ff7d8befe936f5773f9ead5a08b3a5e70a6d
Subproject commit 177752fdc41e8c0326fb328a37e0e113559a3681