From 542fe1c5c62e5ca3386fc09d19efded3c0979727 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 24 Jun 2022 14:58:58 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=83=EF=B8=8F=20modified:=20files/run.s?= =?UTF-8?q?h=20=F0=9F=97=83=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- files/run.sh | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/files/run.sh b/files/run.sh index 3a1ae2d..daa09ac 100644 --- a/files/run.sh +++ b/files/run.sh @@ -1,12 +1,26 @@ #!/bin/bash -if [ "$1" = "healthcheck" ]; then - curl -q -SIs "http://localhost:80" | grep -qE 'HTTP/[1,2]*' && - ls var/run/php-fpm.sock /var/run/mysqld/mysqld.sock /var/run/nginx/nginx.pid &>/dev/null && - exit 0 || exit 1 -fi +__url_check() { + curl -q -SIs "http://localhost:80" | grep -qE 'HTTP/[1,2]*' && return 0 || return 1 +} -[ -f /run-pre.sh ] && /run-pre.sh +__file_check() { + ls var/run/php-fpm.sock /var/run/mysqld/mysqld.sock /var/run/nginx/nginx.pid &>/dev/null && return 0 || return 1 +} + +__mysqld() { + __mysql_test || mysqld_safe --datadir=/var/lib/mysql & + [[ $? = 0 ]] && sleep 10 && return 0 || exit 1 +} + +__mysql_test() { + server_db="$(mysqladmin --silent --wait=30 ping &>/dev/null && echo 'running')" + [[ "$server_db" = "running" ]] && return 0 || return 1 +} + +if [ "$1" = "healthcheck" ]; then + __url_check && __file_check && exit 0 || exit 1 +fi if [ ! -d "/usr/html/wp-admin" ] && [ ! -f "/usr/html/wp-config.php" ]; then echo "[i] Installing wordpress..." @@ -24,8 +38,8 @@ fi if [ ! -d "/var/lib/mysql/mysql" ]; then rm -Rf "/var/lib/mysql/" /usr/bin/mysql_install_db --user=mysql --datadir=/var/lib/mysql - mysqld_safe --datadir=/var/lib/mysql & - mysqladmin --silent --wait=30 ping || exit 1 + __mysqld + __mysql_test mysqladmin -u root password "$DB_PASS" fi @@ -37,10 +51,9 @@ chown -Rf nginx /tmp/nginx chown -Rf mysql:mysql /var/lib/mysql /run/mysqld /usr/bin/php-fpm & -mysqladmin --silent --wait=30 ping || mysqld_safe --datadir=/var/lib/mysql & +__mysql_test || __mysqld if [ ! -d "/var/lib/mysql/wordpress" ]; then - sleep 10 mysql -uroot -p$DB_PASS -e "CREATE DATABASE $DB_NAME" mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON $DB_NAME.* TO $DB_NAME@localhost IDENTIFIED BY '$DB_PASS'" fi