106 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
			
		
		
	
	
			106 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
| #!/command/with-contenv bash
 | |
| 
 | |
| source ContainerTools
 | |
| SNAME=${0##*/}
 | |
| WORKDIR="/app"
 | |
| 
 | |
| # Set user and group IDs
 | |
| if [ -n "$PUID" ]; then
 | |
|     log "Setting User ID for nginx to $PUID"
 | |
|     usermod -o -u "$PUID" nginx
 | |
| fi
 | |
| 
 | |
| if [ -n "$PGID" ]; then
 | |
|     log "Setting Group ID for nginx to $PGID"
 | |
|     groupmod -o -g "$PGID" nginx
 | |
| fi
 | |
| 
 | |
| # 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
 | |
|     ln -s /config/logs/panel $WORKDIR/storage/logs
 | |
| fi
 | |
| 
 | |
| # Check for persistent Nginx logging directory, create file path if not present.
 | |
| if [ ! -d "/config/logs/nginx" ]; then
 | |
|     log "Creating Nginx log directory."
 | |
|     mkdir -p "/config/logs/nginx"
 | |
| fi
 | |
| 
 | |
| # Check for persistent PHP logging directory, create file path if not present.
 | |
| if [ ! -d "/config/logs/php" ]; then
 | |
|     log "Creating PHP log directory."
 | |
|     mkdir -p "/config/logs/php"
 | |
| fi
 | |
| 
 | |
| # Check for persistent Panel logging directory, create file path if not present.
 | |
| if [ ! -d "/config/logs/panel" ]; then
 | |
|     log "Creating PHP log directory."
 | |
|     mkdir -p "/config/logs/panel"
 | |
| 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
 | |
|     else
 | |
|         log "HTTPS Nginx config is already in place"
 | |
|     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
 | |
|     else
 | |
|         log "HTTP Nginx config file is already in place"
 | |
|     fi
 | |
| fi
 | |
| 
 | |
| # Setting permissions for /config
 | |
| log "Making sure permission for config folder are correct"
 | |
| chown -R nginx:nginx /config
 | |
| 
 | |
| log "Initialization complete"
 |