Pterodactyl-Panel/docker/entrypoint.sh

86 lines
2.4 KiB
Bash
Raw Normal View History

2018-05-18 04:53:17 +02:00
#!/bin/ash
2018-08-05 01:21:51 +02:00
## Ensure we are in /app
2018-05-18 15:11:33 +02:00
cd /app
2018-11-11 00:57:49 +01:00
mkdir -p /var/log/panel/logs/ /var/log/supervisord/ /var/log/nginx/ /var/log/php7/ \
2020-04-12 03:01:42 +02:00
&& rm -rf /app/storage/logs/ \
2018-11-11 00:57:49 +01:00
&& chmod 777 /var/log/panel/logs/ \
&& ln -s /var/log/panel/logs/ /app/storage/
2018-08-05 01:21:51 +02:00
## check for .env file and generate app keys if missing
if [ -f /app/var/.env ]; then
2018-11-11 00:57:49 +01:00
echo "external vars exist."
2020-04-12 03:01:42 +02:00
rm -rf /app/.env
2018-08-14 05:33:15 +02:00
2018-08-05 01:21:51 +02:00
ln -s /app/var/.env /app/
else
2018-11-11 00:57:49 +01:00
echo "external vars don't exist."
2020-04-12 03:01:42 +02:00
rm -rf /app/.env
2018-08-14 05:33:15 +02:00
touch /app/var/.env
## manually generate a key because key generate --force fails
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
else
echo -e "APP_KEY exists in environment, using that."
echo -e "APP_KEY=$APP_KEY" > /app/var/.env
fi
2018-08-14 05:33:15 +02:00
ln -s /app/var/.env /app/
2018-08-05 01:21:51 +02:00
fi
2018-05-18 04:53:17 +02:00
2018-11-11 00:57:49 +01: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 03:01:42 +02: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-11 00:57:49 +01:00
else
echo "Checking if letsencrypt email is set."
if [ -z $LE_EMAIL ]; then
2020-04-12 03:01:42 +02:00
echo "No letsencrypt email is set using http config."
cp docker/default.conf /etc/nginx/conf.d/default.conf
2018-11-11 00:57:49 +01:00
else
echo "writing ssl config"
cp docker/default_ssl.conf /etc/nginx/conf.d/default.conf
2018-11-11 00:57:49 +01: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-05 01:21:51 +02:00
## check for DB up before starting the panel
echo "Checking database status."
2018-05-18 04:53:17 +02:00
until nc -z -v -w30 $DB_HOST 3306
2018-08-05 01:21:51 +02:00
2018-05-18 04:53:17 +02:00
do
echo "Waiting for database connection..."
# wait for 5 seconds before check again
sleep 5
done
2018-08-05 01:21:51 +02:00
## make sure the db is set up
2018-11-11 00:57:49 +01:00
echo -e "Migrating and Seeding D.B"
php artisan migrate --force
php artisan db:seed --force
2018-05-18 14:55:12 +02:00
## start cronjobs for the queue
2018-11-11 00:57:49 +01:00
echo -e "Starting cron jobs."
crond -L /var/log/crond -l 5
2018-05-18 14:55:12 +02:00
2020-04-12 03:48:22 +02:00
## install yarn stuff
yarn install --production
yarn add cross-env
yarn run build:production
2018-11-11 00:57:49 +01:00
echo -e "Starting supervisord."
exec "$@"