2018-05-18 02:53:17 +00:00
|
|
|
#!/bin/ash
|
2018-08-04 23:21:51 +00:00
|
|
|
## Ensure we are in /app
|
|
|
|
|
2018-05-18 13:11:33 +00:00
|
|
|
cd /app
|
|
|
|
|
2018-11-10 23:57:49 +00:00
|
|
|
mkdir -p /var/log/panel/logs/ /var/log/supervisord/ /var/log/nginx/ /var/log/php7/ \
|
2020-04-12 01:01:42 +00:00
|
|
|
&& rm -rf /app/storage/logs/ \
|
2018-11-10 23:57:49 +00:00
|
|
|
&& chmod 777 /var/log/panel/logs/ \
|
|
|
|
&& ln -s /var/log/panel/logs/ /app/storage/
|
|
|
|
|
2018-08-04 23:21:51 +00:00
|
|
|
## check for .env file and generate app keys if missing
|
|
|
|
if [ -f /app/var/.env ]; then
|
2018-11-10 23:57:49 +00:00
|
|
|
echo "external vars exist."
|
2020-04-12 01:01:42 +00:00
|
|
|
rm -rf /app/.env
|
2018-08-14 03:33:15 +00:00
|
|
|
|
2018-08-04 23:21:51 +00:00
|
|
|
ln -s /app/var/.env /app/
|
|
|
|
else
|
2018-11-10 23:57:49 +00:00
|
|
|
echo "external vars don't exist."
|
2020-04-12 01:01:42 +00:00
|
|
|
rm -rf /app/.env
|
2018-08-14 03:33:15 +00:00
|
|
|
touch /app/var/.env
|
|
|
|
|
|
|
|
## manually generate a key because key generate --force fails
|
2020-11-06 13:23:05 +00:00
|
|
|
if [ -z $APP_KEY ]; then
|
|
|
|
echo -e "Generating key."
|
|
|
|
APP_KEY=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
|
|
|
|
echo -e "Generated app key: $APP_KEY"
|
|
|
|
echo -e "APP_KEY=$APP_KEY" > /app/var/.env
|
2020-11-06 13:21:09 +00:00
|
|
|
else
|
|
|
|
echo -e "APP_KEY exists in environment, using that."
|
|
|
|
echo -e "APP_KEY=$APP_KEY" > /app/var/.env
|
|
|
|
fi
|
2018-08-14 03:33:15 +00:00
|
|
|
|
|
|
|
ln -s /app/var/.env /app/
|
2018-08-04 23:21:51 +00:00
|
|
|
fi
|
2018-05-18 02:53:17 +00:00
|
|
|
|
2018-11-10 23:57:49 +00:00
|
|
|
echo "Checking if https is required."
|
|
|
|
if [ -f /etc/nginx/conf.d/default.conf ]; then
|
|
|
|
echo "Using nginx config already in place."
|
2020-04-12 01:01:42 +00:00
|
|
|
if [ $LE_EMAIL ]; then
|
|
|
|
echo "Checking for cert update"
|
|
|
|
certbot certonly -d $(echo $APP_URL | sed 's~http[s]*://~~g') --standalone -m $LE_EMAIL --agree-tos -n
|
|
|
|
else
|
|
|
|
echo "No letsencrypt email is set"
|
|
|
|
fi
|
2018-11-10 23:57:49 +00:00
|
|
|
else
|
|
|
|
echo "Checking if letsencrypt email is set."
|
|
|
|
if [ -z $LE_EMAIL ]; then
|
2020-04-12 01:01:42 +00:00
|
|
|
echo "No letsencrypt email is set using http config."
|
2020-04-12 20:02:48 +00:00
|
|
|
cp docker/default.conf /etc/nginx/conf.d/default.conf
|
2018-11-10 23:57:49 +00:00
|
|
|
else
|
|
|
|
echo "writing ssl config"
|
2020-04-12 20:02:48 +00:00
|
|
|
cp docker/default_ssl.conf /etc/nginx/conf.d/default.conf
|
2018-11-10 23:57:49 +00:00
|
|
|
echo "updating ssl config for domain"
|
|
|
|
sed -i "s|<domain>|$(echo $APP_URL | sed 's~http[s]*://~~g')|g" /etc/nginx/conf.d/default.conf
|
|
|
|
echo "generating certs"
|
|
|
|
certbot certonly -d $(echo $APP_URL | sed 's~http[s]*://~~g') --standalone -m $LE_EMAIL --agree-tos -n
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-08-04 23:21:51 +00:00
|
|
|
## check for DB up before starting the panel
|
2018-08-18 11:32:01 +00:00
|
|
|
echo "Checking database status."
|
2018-05-18 02:53:17 +00:00
|
|
|
until nc -z -v -w30 $DB_HOST 3306
|
2018-08-04 23:21:51 +00:00
|
|
|
|
2018-05-18 02:53:17 +00:00
|
|
|
do
|
|
|
|
echo "Waiting for database connection..."
|
|
|
|
# wait for 5 seconds before check again
|
|
|
|
sleep 5
|
|
|
|
done
|
|
|
|
|
2018-08-04 23:21:51 +00:00
|
|
|
## make sure the db is set up
|
2018-11-10 23:57:49 +00:00
|
|
|
echo -e "Migrating and Seeding D.B"
|
2018-09-16 01:22:13 +00:00
|
|
|
php artisan migrate --force
|
|
|
|
php artisan db:seed --force
|
2018-05-18 12:55:12 +00:00
|
|
|
|
2018-09-16 01:22:13 +00:00
|
|
|
## start cronjobs for the queue
|
2018-11-10 23:57:49 +00:00
|
|
|
echo -e "Starting cron jobs."
|
|
|
|
crond -L /var/log/crond -l 5
|
2018-05-18 12:55:12 +00:00
|
|
|
|
2020-04-12 01:48:22 +00:00
|
|
|
## install yarn stuff
|
|
|
|
yarn install --production
|
|
|
|
yarn add cross-env
|
|
|
|
yarn run build:production
|
|
|
|
|
2018-11-10 23:57:49 +00:00
|
|
|
echo -e "Starting supervisord."
|
2020-11-06 13:21:09 +00:00
|
|
|
exec "$@"
|