🗃️ modified: files/run.sh 🗃️

This commit is contained in:
Jason 2022-06-24 15:58:13 -04:00
parent 02e7af7420
commit 3d9d5e0370
No known key found for this signature in database
GPG Key ID: 4F765975C1F0EE5F

View File

@ -8,13 +8,35 @@ __file_check() {
ls var/run/php-fpm.sock /var/run/mysqld/mysqld.sock /var/run/nginx/nginx.pid &>/dev/null && return 0 || return 1 ls var/run/php-fpm.sock /var/run/mysqld/mysqld.sock /var/run/nginx/nginx.pid &>/dev/null && return 0 || return 1
} }
__phpfpm() {
if [ -f "/var/run/php-fpm.sock" ]; then
return 0
else
echo "[i] Starting php-fpm..."
/usr/bin/php-fpm &
if [[ $? = 0 ]]; then
sleep 10
return 0
else
exit 1
fi
fi
}
__mysqld() { __mysqld() {
__mysql_test || mysqld_safe --datadir=/var/lib/mysql & if ! __mysql_test; then
[[ $? = 0 ]] && sleep 10 && return 0 || exit 1 mysqld_safe --datadir=/var/lib/mysql &
fi
if [[ $? = 0 ]]; then
sleep 5
return 0
else
exit 1
fi
} }
__mysql_test() { __mysql_test() {
server_db="$(mysqladmin --silent --wait=30 ping &>/dev/null && echo 'running')" server_db="$(mysqladmin --silent --wait=2 ping &>/dev/null && echo 'running')"
[[ "$server_db" = "running" ]] && return 0 || return 1 [[ "$server_db" = "running" ]] && return 0 || return 1
} }
@ -37,11 +59,13 @@ fi
if [ -d "/var/lib/wordpress/devel" ]; then if [ -d "/var/lib/wordpress/devel" ]; then
echo "[i] Initializing plugin development dir" echo "[i] Initializing plugin development dir"
plugins="$(ls /var/lib/wordpress/devel)" plugins="$(ls /var/lib/wordpress/devel 2>/dev/null || false)"
[ -d "/usr/html/wp-content/plugins" ] || mkdir -p "/usr/html/wp-content/plugins" [ -d "/usr/html/wp-content/plugins" ] || mkdir -p "/usr/html/wp-content/plugins"
for d in $plugins; do if [ -n "$plugins" ]; then
ln -sf "/var/lib/wordpress/devel/$d" "/usr/html/wp-content/plugins/$d" for d in $plugins; do
done ln -sf "/var/lib/wordpress/devel/$d" "/usr/html/wp-content/plugins/$d"
done
fi
fi fi
if [ ! -d "/var/lib/mysql/mysql" ]; then if [ ! -d "/var/lib/mysql/mysql" ]; then
@ -53,18 +77,20 @@ if [ ! -d "/var/lib/mysql/mysql" ]; then
mysqladmin -u root password "$DB_PASS" mysqladmin -u root password "$DB_PASS"
fi fi
echo "[i] Creating directories..."
mkdir -p /usr/logs/php8 mkdir -p /usr/logs/php8
mkdir -p /usr/logs/nginx mkdir -p /usr/logs/nginx
mkdir -p /tmp/nginx mkdir -p /tmp/nginx
echo "[i] Setting permissions..."
chown -Rf nginx /tmp/nginx chown -Rf nginx /tmp/nginx
chown -Rf mysql:mysql /var/lib/mysql /run/mysqld chown -Rf mysql:mysql /var/lib/mysql /run/mysqld
/usr/bin/php-fpm & echo "[i] Starting mysql database server..."
__mysql_test || __mysqld __mysql_test || __mysqld
if [ ! -d "/var/lib/mysql/wordpress" ]; then if [ ! -d "/var/lib/mysql/wordpress" ]; then
echo "[i] Creating word database" echo "[i] Creating word database..."
mysql -uroot -p$DB_PASS -e "CREATE DATABASE $DB_NAME" 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'" mysql -uroot -p$DB_PASS -e "GRANT ALL PRIVILEGES ON $DB_NAME.* TO $DB_NAME@localhost IDENTIFIED BY '$DB_PASS'"
fi fi
@ -74,4 +100,5 @@ fi
[ -z "$DB_USER" ] && echo "Database user: not set" || echo "Database user: $DB_USER" [ -z "$DB_USER" ] && echo "Database user: not set" || echo "Database user: $DB_USER"
[ -z "$DB_PASS" ] && echo "Database pass: not set" || echo "Database pass: $DB_PASS" [ -z "$DB_PASS" ] && echo "Database pass: not set" || echo "Database pass: $DB_PASS"
echo "[i] Starting web server..."
nginx nginx