#!/command/with-contenv bash source ContainerTools SNAME=${0##*/} WORKDIR="/var/www/pterodactyl" # If DBHOST value is present, pause boot until target container is up. if [ -n "$DBHOST" ]; then log "Waiting for SQL at $DBHOST:${DBPORT:=3306}" if wait-for-it $DBHOST:$DBPORT -q -t ${TESTTIME:=30}; then log "SQL found, continuing" else log "SQL could not be reached! Exiting..." exit 1 fi fi # If REDISHOST value is present, pause boot until target container is up. if [ -n "$REDISHOST" ]; then log "Waiting for Redis at $REDISHOST:${REDISPORT:=6379}" if wait-for-it $REDISHOST:$REDISPORT -q -t ${TESTTIME:=30}; then log "Redis found, continuing" else log "Redis could not be reached! Exiting..." exit 1 fi fi # Check for persistent storage directory, create file structure if not present. if [ ! -d "/config/storage" ]; then log "Creating storage directory" cat $WORKDIR/.storage.tmpl | while read line; do mkdir -p "/config/${line}" done fi # Check for persistent logging directory, create file path if not present. if [ ! -d "/config/log/nginx" ]; then log "Creating log directory." mkdir -p "/config/log/nginx" fi # Check for config file, create template if not present. if [ ! -e /config/pterodactyl.conf ]; then log "Config file does not exist, creating template" log "[WARN] Connect to container and finish setup process" cp $WORKDIR/.env.example /config/pterodactyl.conf log "Generating unique Pterodactyl key" log "$(php $WORKDIR/artisan key:generate --force --no-interaction)" fi # Clear views and autogenerated configs on launch. This is necessary for updates, and doesn't affect non-update launches. log "$(php $WORKDIR/artisan view:clear)" log "$(php $WORKDIR/artisan config:clear)" log "Checking for database updates, preparing cache" log "[NOTE] This will fail if the database connection has not yet been configured" log "$(php $WORKDIR/artisan migrate --seed --force)" chown -R nginx:nginx /config/ # Load selected Nginx conf. if [ "$HTTPS" == "true" ]; then if [ ! -e "/etc/nginx/http.d/pterodactyl.conf" ]; then log "Symlinking Nginx config file for HTTPS" ln -s /defaults/nginx/https.conf /etc/nginx/http.d/pterodactyl.conf fi else if [ ! -e "/etc/nginx/http.d/pterodactyl.conf" ]; then log "Symlinking Nginx config file for HTTP" ln -s /defaults/nginx/http.conf /etc/nginx/http.d/pterodactyl.conf fi fi log "Initialization complete"