cloud-apache-container/scripts/entrypoint.sh

61 lines
1.9 KiB
Bash

#!/bin/bash
if [ -z "$PHPVER" ]; then
PHPVER="81";
fi
adduser -u $uid $user
mkdir -p /home/$user/public_html
chown -R $user:$user /home/$user
chmod -R 755 /home/$user
/scripts/install-php$PHPVER.sh
/scripts/create-vhost.sh
/scripts/create-php-config.sh
/usr/sbin/httpd -k start
/usr/sbin/php-fpm -y /etc/php-fpm.conf
if [[ $environment == 'DEV' ]]; then
echo "Starting Dev Deployment"
dnf install -y cronie
/usr/sbin/crond
mkdir -p /home/$user/public_html/_db_backups
dnf install -y MariaDB-server MariaDB-client memcached
nohup mysqld -umysql &
if [ ! -f /var/lib/mysql/creds ]; then
echo "Give MySQL a chance to finish starting..."
sleep 10
mysql_user=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 13 ; echo '')
mysql_password=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 18 ; echo '')
mysql_db=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 6 ; echo '')
mysql -e "CREATE DATABASE devdb_"$mysql_db";"
mysql -e "CREATE USER '"$mysql_user"'@'localhost' IDENTIFIED BY '"$mysql_password"';"
mysql -e "GRANT ALL PRIVILEGES ON *.* TO '"$mysql_user"'@'localhost' WITH GRANT OPTION;"
mysql -e "FLUSH PRIVILEGES;"
dt=$(date +%y%m%d-%T)
echo "*/15 * * * * root /usr/bin/mysqldump $mysql_db > /home/$user/public_html/_db_backups/$mysql_db.$dt.sql" >> /etc/crontab
echo "*/30 * * * * root /usr/bin/find /home/$user/public_html/_db_backups/ -type f -mmin +360 -delete" >> /etc/crontab
-type f -mmin +360
echo "MySQL User: "$mysql_user > /var/lib/mysql/creds
echo "MySQL Password: "$mysql_password >> /var/lib/mysql/creds
echo "MySQL Database: devdb_"$mysql_db >> /var/lib/mysql/creds
cat /var/lib/mysql/creds
fi
/usr/bin/memcached -d -u $user
fi
if [[ $environment == 'PROD' ]]; then
sed -r -i 's/;session.save_path="localhost:11211/session.save_path="memcache:11211/' /etc/php.d/50-memcached.ini
fi
tail -f /etc/httpd/logs/*
exit 0