generated from oci/template
it builds, and hopefully runs?
All checks were successful
Build Docker Image on Commit / build-and-publish (push) Successful in 2m53s
All checks were successful
Build Docker Image on Commit / build-and-publish (push) Successful in 2m53s
This commit is contained in:
parent
ba547a2130
commit
d7a6b77e57
13 changed files with 1382 additions and 519 deletions
425
entrypoint.sh
425
entrypoint.sh
|
@ -1,130 +1,331 @@
|
|||
#!/bin/bash
|
||||
|
||||
# TAK Server Unified Entrypoint Script
|
||||
# This script handles both TAK Server and Database modes
|
||||
|
||||
set -e
|
||||
|
||||
TAK_ARCHIVE_PATH="${TAK_ARCHIVE_PATH:-/tak-archive/takserver-docker-5.4-RELEASE-19.zip}"
|
||||
TAK_ARCHIVE_DIR="/tak-archive"
|
||||
TAK_INSTALL_DIR="/opt/tak"
|
||||
TAK_MODE="${TAK_MODE:-server}"
|
||||
# Colors for logging
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Function to log messages
|
||||
log() {
|
||||
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
|
||||
log_info() {
|
||||
echo -e "${GREEN}[INFO]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1"
|
||||
}
|
||||
|
||||
# Function to find the latest TAK archive
|
||||
find_latest_tak_archive() {
|
||||
local latest_archive=""
|
||||
|
||||
# Check if the specific archive exists
|
||||
if [ -f "$TAK_ARCHIVE_PATH" ]; then
|
||||
log "Found specified TAK archive: $TAK_ARCHIVE_PATH"
|
||||
echo "$TAK_ARCHIVE_PATH"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Look for any takserver-docker-*.zip files in the archive directory
|
||||
if [ -d "$TAK_ARCHIVE_DIR" ]; then
|
||||
latest_archive=$(find "$TAK_ARCHIVE_DIR" -name "takserver-docker-*.zip" -type f | sort -V | tail -n 1)
|
||||
|
||||
if [ -n "$latest_archive" ]; then
|
||||
log "Found latest TAK archive: $latest_archive"
|
||||
echo "$latest_archive"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
|
||||
# If no archive found, return empty
|
||||
echo ""
|
||||
return 1
|
||||
log_warn() {
|
||||
echo -e "${YELLOW}[WARN]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1"
|
||||
}
|
||||
|
||||
# Function to check if TAK is already installed
|
||||
is_tak_installed() {
|
||||
if [ "$TAK_MODE" = "database" ]; then
|
||||
[ -f "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh" ] && [ -x "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh" ]
|
||||
else
|
||||
[ -f "$TAK_INSTALL_DIR/configureInDocker.sh" ] && [ -x "$TAK_INSTALL_DIR/configureInDocker.sh" ]
|
||||
fi
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1"
|
||||
}
|
||||
|
||||
# Function to extract TAK archive
|
||||
extract_tak_archive() {
|
||||
local archive_path
|
||||
archive_path=$(find_latest_tak_archive)
|
||||
|
||||
if [ -z "$archive_path" ]; then
|
||||
log "ERROR: No TAK archive found"
|
||||
log "Please mount your TAK Server archive to the /tak-archive directory."
|
||||
log "Expected format: takserver-docker-X.X-RELEASE-XX.zip"
|
||||
log "Example: docker run -v /path/to/takserver-docker-5.4-RELEASE-19.zip:/tak-archive/takserver-docker-5.4-RELEASE-19.zip ..."
|
||||
log "Or mount the directory: docker run -v /path/to/tak-archives:/tak-archive ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log "Extracting TAK archive from $archive_path"
|
||||
|
||||
# Create temporary directory for extraction
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
|
||||
# Extract the archive (handling both .zip and .tar.gz formats)
|
||||
if [[ "$archive_path" == *.zip ]]; then
|
||||
unzip -q "$archive_path" -d "$TEMP_DIR"
|
||||
else
|
||||
tar -xzf "$archive_path" -C "$TEMP_DIR"
|
||||
fi
|
||||
|
||||
# Copy the tak folder contents to /opt/tak
|
||||
if [ -d "$TEMP_DIR/tak" ]; then
|
||||
log "Copying TAK files to $TAK_INSTALL_DIR"
|
||||
cp -r "$TEMP_DIR/tak/"* "$TAK_INSTALL_DIR/"
|
||||
|
||||
# Set proper permissions
|
||||
[ -f "$TAK_INSTALL_DIR/configureInDocker.sh" ] && chmod +x "$TAK_INSTALL_DIR/configureInDocker.sh"
|
||||
[ -f "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh" ] && chmod +x "$TAK_INSTALL_DIR/db-utils/configureInDocker.sh"
|
||||
|
||||
# Clean up temporary directory
|
||||
rm -rf "$TEMP_DIR"
|
||||
|
||||
log "TAK archive extracted successfully"
|
||||
else
|
||||
log "ERROR: TAK archive does not contain expected 'tak' folder structure"
|
||||
log "Archive contents:"
|
||||
ls -la "$TEMP_DIR"
|
||||
rm -rf "$TEMP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
log_debug() {
|
||||
echo -e "${BLUE}[DEBUG]${NC} $(date '+%Y-%m-%d %H:%M:%S') - $1"
|
||||
}
|
||||
|
||||
# Main execution
|
||||
if [ "$TAK_MODE" = "database" ]; then
|
||||
log "Starting TAK Server Database container..."
|
||||
else
|
||||
log "Starting TAK Server container..."
|
||||
fi
|
||||
log_info "Starting TAK Server Hybrid Container..."
|
||||
|
||||
# Check if TAK is already installed
|
||||
if ! is_tak_installed; then
|
||||
log "TAK not found in $TAK_INSTALL_DIR, checking for archive..."
|
||||
extract_tak_archive
|
||||
else
|
||||
log "TAK already installed in $TAK_INSTALL_DIR"
|
||||
fi
|
||||
# Source helper scripts
|
||||
log_debug "Sourcing helper scripts..."
|
||||
source /scripts/tak-version.sh
|
||||
log_debug "Helper scripts loaded successfully"
|
||||
|
||||
# Verify TAK installation
|
||||
if ! is_tak_installed; then
|
||||
log "ERROR: TAK installation verification failed"
|
||||
# Check if TAK server files are provided
|
||||
log_info "Checking for TAK server files..."
|
||||
log_debug "Looking for files in /takserver-zip directory..."
|
||||
|
||||
if [ ! -d "/takserver-zip" ]; then
|
||||
log_error "Mount point /takserver-zip does not exist!"
|
||||
log_error "Please ensure you mount a directory containing TAK server files"
|
||||
log_error "Example: docker run -v /path/to/tak/files:/takserver-zip:ro ..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Execute the appropriate command based on mode
|
||||
if [ "$TAK_MODE" = "database" ]; then
|
||||
log "Starting TAK Database configuration"
|
||||
exec /opt/tak/db-utils/configureInDocker.sh
|
||||
else
|
||||
log "Starting TAK Server with configureInDocker.sh init"
|
||||
exec /bin/bash -c "/opt/tak/configureInDocker.sh init &>> /opt/tak/logs/takserver.log"
|
||||
# Check if directory is empty
|
||||
if [ ! "$(ls -A /takserver-zip 2>/dev/null)" ]; then
|
||||
log_error "Directory /takserver-zip is empty!"
|
||||
log_error "Please place takserver-docker-X.Y-RELEASE-Z.zip files in the mounted directory"
|
||||
log_debug "Directory contents:"
|
||||
ls -l /takserver-zip/ || log_debug "Cannot list directory contents"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# List all files in the directory for debugging
|
||||
log_debug "Contents of /takserver-zip:"
|
||||
ls -l /takserver-zip/ | while read line; do
|
||||
log_debug " $line"
|
||||
done
|
||||
|
||||
# Check for zip files specifically
|
||||
ZIP_COUNT=$(find /takserver-zip -name "*.zip" -type f | wc -l)
|
||||
log_debug "Found $ZIP_COUNT zip files in /takserver-zip"
|
||||
|
||||
if [ $ZIP_COUNT -eq 0 ]; then
|
||||
log_error "No zip files found in /takserver-zip!"
|
||||
log_error "Please ensure you have takserver-docker-X.Y-RELEASE-Z.zip files"
|
||||
log_debug "Available files:"
|
||||
find /takserver-zip -type f | while read file; do
|
||||
log_debug " $(basename $file)"
|
||||
done
|
||||
while true; do sleep 3600; done
|
||||
fi
|
||||
|
||||
# Check for TAK server specific zip files
|
||||
TAK_ZIP_COUNT=$(find /takserver-zip -name "takserver-docker-*-RELEASE-*.zip" -type f | wc -l)
|
||||
log_debug "Found $TAK_ZIP_COUNT TAK server zip files"
|
||||
|
||||
if [ $TAK_ZIP_COUNT -eq 0 ]; then
|
||||
log_error "No TAK server zip files found matching pattern 'takserver-docker-*-RELEASE-*.zip'!"
|
||||
log_error "Available zip files:"
|
||||
find /takserver-zip -name "*.zip" -type f | while read file; do
|
||||
log_error " $(basename $file)"
|
||||
done
|
||||
log_error "Required format: takserver-docker-X.Y-RELEASE-Z.zip"
|
||||
log_error "Example: takserver-docker-5.4-RELEASE-19.zip"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Use the helper script to find the latest TAK release
|
||||
log_info "Finding latest TAK server release..."
|
||||
LATEST_ZIP=$(find_latest_tak_release /takserver-zip)
|
||||
if [ $? -ne 0 ]; then
|
||||
log_error "Failed to find latest TAK release: $LATEST_ZIP"
|
||||
log_info "Available TAK releases:"
|
||||
list_tak_releases /takserver-zip
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "Found latest TAK server release: $(basename $LATEST_ZIP)"
|
||||
log_info "Version: $(get_tak_version $LATEST_ZIP)"
|
||||
log_debug "Full path: $LATEST_ZIP"
|
||||
|
||||
# Extract the zip file if not already extracted
|
||||
if [ ! -f /opt/tak/configureInDocker.sh ]; then
|
||||
log_info "TAK server files not found - extracting from ZIP..."
|
||||
log_debug "Using extraction script: /scripts/tak-extract.sh"
|
||||
|
||||
# Use the extraction script
|
||||
if /scripts/tak-extract.sh extract "$LATEST_ZIP" /opt/tak; then
|
||||
log_info "TAK server extraction completed successfully"
|
||||
|
||||
# Set proper permissions
|
||||
/scripts/tak-extract.sh permissions /opt/tak tak:tak
|
||||
|
||||
# Verify installation
|
||||
if /scripts/tak-extract.sh verify /opt/tak; then
|
||||
log_info "TAK server installation verified"
|
||||
else
|
||||
log_error "TAK server installation verification failed!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_error "Failed to extract TAK server files!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_info "TAK server files already exist - skipping extraction"
|
||||
log_debug "Found existing configureInDocker.sh at /opt/tak/configureInDocker.sh"
|
||||
|
||||
# Ensure permissions are correct on existing files
|
||||
log_debug "Ensuring correct permissions on existing TAK files..."
|
||||
/scripts/tak-extract.sh permissions /opt/tak tak:tak
|
||||
fi
|
||||
|
||||
# Start PostgreSQL
|
||||
log_info "Starting PostgreSQL..."
|
||||
|
||||
# Initialize PostgreSQL if not already done
|
||||
if [ ! -f /var/lib/postgresql/15/main/PG_VERSION ]; then
|
||||
log_info "Initializing PostgreSQL database cluster..."
|
||||
if sudo -u postgres /usr/lib/postgresql/15/bin/initdb -D /var/lib/postgresql/15/main; then
|
||||
log_info "PostgreSQL initialized successfully"
|
||||
|
||||
# Configure PostgreSQL
|
||||
log_info "Configuring PostgreSQL..."
|
||||
|
||||
# Create postgresql.conf
|
||||
log_debug "Creating postgresql.conf..."
|
||||
cat > /tmp/postgresql.conf <<EOF
|
||||
listen_addresses = '*'
|
||||
port = 5432
|
||||
max_connections = 100
|
||||
shared_buffers = 128MB
|
||||
log_timezone = 'UTC'
|
||||
timezone = 'UTC'
|
||||
EOF
|
||||
sudo -u postgres cp /tmp/postgresql.conf /var/lib/postgresql/15/main/postgresql.conf
|
||||
|
||||
# Create pg_hba.conf
|
||||
log_debug "Creating pg_hba.conf..."
|
||||
cat > /tmp/pg_hba.conf <<EOF
|
||||
# PostgreSQL Client Authentication Configuration File
|
||||
local all all trust
|
||||
host all all 127.0.0.1/32 trust
|
||||
host all all ::1/128 trust
|
||||
host all all 0.0.0.0/0 md5
|
||||
EOF
|
||||
sudo -u postgres cp /tmp/pg_hba.conf /var/lib/postgresql/15/main/pg_hba.conf
|
||||
|
||||
# Verify config files were created
|
||||
if [ -f /var/lib/postgresql/15/main/postgresql.conf ]; then
|
||||
log_debug "postgresql.conf created successfully"
|
||||
else
|
||||
log_error "Failed to create postgresql.conf!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f /var/lib/postgresql/15/main/pg_hba.conf ]; then
|
||||
log_debug "pg_hba.conf created successfully"
|
||||
else
|
||||
log_error "Failed to create pg_hba.conf!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
log_info "PostgreSQL configuration completed"
|
||||
else
|
||||
log_error "Failed to initialize PostgreSQL!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_info "PostgreSQL already initialized"
|
||||
|
||||
# Check if config files exist, create them if they don't
|
||||
if [ ! -f /var/lib/postgresql/15/main/postgresql.conf ]; then
|
||||
log_info "Creating missing postgresql.conf..."
|
||||
|
||||
# Create postgresql.conf
|
||||
log_debug "Creating postgresql.conf..."
|
||||
cat > /tmp/postgresql.conf <<EOF
|
||||
listen_addresses = '*'
|
||||
port = 5432
|
||||
max_connections = 100
|
||||
shared_buffers = 128MB
|
||||
log_timezone = 'UTC'
|
||||
timezone = 'UTC'
|
||||
EOF
|
||||
sudo -u postgres cp /tmp/postgresql.conf /var/lib/postgresql/15/main/postgresql.conf
|
||||
fi
|
||||
|
||||
if [ ! -f /var/lib/postgresql/15/main/pg_hba.conf ]; then
|
||||
log_info "Creating missing pg_hba.conf..."
|
||||
|
||||
# Create pg_hba.conf
|
||||
log_debug "Creating pg_hba.conf..."
|
||||
cat > /tmp/pg_hba.conf <<EOF
|
||||
# PostgreSQL Client Authentication Configuration File
|
||||
local all all trust
|
||||
host all all 127.0.0.1/32 trust
|
||||
host all all ::1/128 trust
|
||||
host all all 0.0.0.0/0 md5
|
||||
EOF
|
||||
sudo -u postgres cp /tmp/pg_hba.conf /var/lib/postgresql/15/main/pg_hba.conf
|
||||
fi
|
||||
|
||||
log_debug "Configuration files checked/created"
|
||||
fi
|
||||
|
||||
# Start PostgreSQL server
|
||||
log_info "Starting PostgreSQL server..."
|
||||
|
||||
# Verify config files exist before starting
|
||||
log_debug "Checking configuration files..."
|
||||
if [ -f /var/lib/postgresql/15/main/postgresql.conf ]; then
|
||||
log_debug "postgresql.conf exists"
|
||||
else
|
||||
log_error "postgresql.conf missing!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -f /var/lib/postgresql/15/main/pg_hba.conf ]; then
|
||||
log_debug "pg_hba.conf exists"
|
||||
else
|
||||
log_error "pg_hba.conf missing!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Show the contents of the data directory
|
||||
log_debug "Contents of PostgreSQL data directory:"
|
||||
ls -la /var/lib/postgresql/15/main/ | while read line; do
|
||||
log_debug " $line"
|
||||
done
|
||||
|
||||
# Start PostgreSQL with verbose logging to catch any errors
|
||||
log_debug "Starting PostgreSQL with command: sudo -u postgres /usr/lib/postgresql/15/bin/postgres -D /var/lib/postgresql/15/main"
|
||||
sudo -u postgres /usr/lib/postgresql/15/bin/postgres -D /var/lib/postgresql/15/main &
|
||||
POSTGRES_PID=$!
|
||||
log_debug "PostgreSQL started with PID: $POSTGRES_PID"
|
||||
|
||||
# Give PostgreSQL a moment to start
|
||||
sleep 2
|
||||
|
||||
# Check if the process is still running
|
||||
if kill -0 $POSTGRES_PID 2>/dev/null; then
|
||||
log_debug "PostgreSQL process is still running"
|
||||
else
|
||||
log_error "PostgreSQL process died immediately!"
|
||||
log_error "Checking system logs for errors..."
|
||||
# Try to get any error output
|
||||
journalctl -u postgresql --no-pager --lines=10 2>/dev/null || log_debug "No journalctl available"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Wait for PostgreSQL to start and setup database
|
||||
log_info "Waiting for PostgreSQL to be ready..."
|
||||
POSTGRES_READY=0
|
||||
for i in {1..30}; do
|
||||
if pg_isready -h localhost -p 5432 >/dev/null 2>&1; then
|
||||
POSTGRES_READY=1
|
||||
log_info "PostgreSQL is ready after ${i} seconds"
|
||||
break
|
||||
fi
|
||||
log_debug "PostgreSQL not ready yet, waiting... (attempt $i/30)"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ $POSTGRES_READY -eq 0 ]; then
|
||||
log_error "PostgreSQL failed to become ready after 30 seconds!"
|
||||
log_error "Checking PostgreSQL process status..."
|
||||
if kill -0 $POSTGRES_PID 2>/dev/null; then
|
||||
log_error "PostgreSQL process is running but not accepting connections"
|
||||
else
|
||||
log_error "PostgreSQL process has died"
|
||||
fi
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Use the database setup script
|
||||
log_info "Setting up database..."
|
||||
if /scripts/db-setup.sh setup; then
|
||||
log_info "Database setup completed successfully"
|
||||
else
|
||||
log_error "Database setup failed!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run database configuration if it exists
|
||||
if [ -f "/opt/tak/db-utils/configureInDocker.sh" ]; then
|
||||
log_info "Configuring TAK database..."
|
||||
/opt/tak/db-utils/configureInDocker.sh &
|
||||
DB_CONFIG_PID=$!
|
||||
log_debug "TAK database configuration started with PID: $DB_CONFIG_PID"
|
||||
sleep 10
|
||||
else
|
||||
log_warn "TAK database configuration script not found, skipping..."
|
||||
fi
|
||||
|
||||
# Start TAK server
|
||||
if [ -f "/opt/tak/configureInDocker.sh" ]; then
|
||||
log_info "Starting TAK server..."
|
||||
log_debug "Executing: /opt/tak/configureInDocker.sh init"
|
||||
exec /opt/tak/configureInDocker.sh init
|
||||
else
|
||||
log_error "TAK server configuration script not found!"
|
||||
log_error "Expected file: /opt/tak/configureInDocker.sh"
|
||||
log_error "The extracted TAK server files may be incomplete or corrupted."
|
||||
log_debug "Contents of /opt/tak:"
|
||||
ls -la /opt/tak/ | while read line; do
|
||||
log_debug " $line"
|
||||
done
|
||||
exit 1
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue