Commit d8a40880 authored by Andreas Düren's avatar Andreas Düren
Browse files

Improve start.sh with Cloudron best practices

parent 789d7028
Loading
Loading
Loading
Loading
+56 −24
Original line number Diff line number Diff line
#!/bin/bash

# Better signal handling - forward signals to child processes
trap 'kill -TERM $SERVER_PID; kill -TERM $NGINX_PID; exit' TERM INT

set -eu

echo "==> Starting Ente Cloudron app..."

# Create necessary directories
mkdir -p /app/data/config /app/data/storage /app/data/nginx/tmp /app/data/go /app/data/logs
mkdir -p /app/data/config /app/data/storage /app/data/nginx/tmp /app/data/go /app/data/logs /run/nginx

# Add comment about Cloudron filesystem limitations
echo "==> NOTE: Running in Cloudron environment with limited write access"
echo "==> Writable directories: /app/data, /tmp, /run"

# One-time initialization tracking
if [[ ! -f /app/data/.initialized ]]; then
    echo "==> Fresh installation, setting up data directory..."
    
    echo "==> DEBUG: Full repository structure at /app/code"
    find /app/code -type d -maxdepth 3 -not -path "*/node_modules/*" -not -path "*/\.*" | sort
@@ -28,7 +41,6 @@ else
    fi
    
    # Create config template file on first run
if [[ ! -f /app/data/config/config.yaml ]]; then
    echo "==> First run - creating configuration template"
    
    # Generate random secrets
@@ -97,6 +109,10 @@ S3_SECRET_KEY=aPdHB4fkvQAuJUqPhneoIDcHEHee9cvP2j0nKSly
S3_PREFIX=ente/
EOT
    echo "==> Test S3 configuration created for Wasabi"
    
    # Mark initialization as complete
    touch /app/data/.initialized
    echo "==> Initialization complete"
fi

# Check if s3.env exists
@@ -342,6 +358,16 @@ export ENTE_LOG_LEVEL=debug
echo "==> Testing API connectivity"
curl -v http://localhost:8000/api/health || echo "API not yet available, this is normal during startup"

# Determine available memory and set limits accordingly
if [[ -f /sys/fs/cgroup/cgroup.controllers ]]; then # cgroup v2
    memory_limit=$(cat /sys/fs/cgroup/memory.max)
    [[ "${memory_limit}" == "max" ]] && memory_limit=$(( 2 * 1024 * 1024 * 1024 )) # "max" really means unlimited
else
    memory_limit=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes) # this is the RAM. we have equal amount of swap
fi
memory_mb=$((memory_limit/1024/1024))
echo "==> Available memory: ${memory_mb}MB"

# Set up database environment variables and ensure proper SSL config
export ENTE_DB_USER="${CLOUDRON_POSTGRESQL_USERNAME}"
export ENTE_DB_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
@@ -361,10 +387,7 @@ export REMOTE_STORAGE_PREFIX="${S3_PREFIX:-ente/}"

# Change ownership to cloudron user
chown -R cloudron:cloudron /app/data

# Add comment about Cloudron filesystem limitations
echo "==> NOTE: Running in Cloudron environment with limited write access"
echo "==> Writable directories: /app/data, /tmp, /run"
chown -R cloudron:cloudron /run/nginx

# Start Museum server on port 8000 (different from the NGINX port 8080)
echo "==> Starting Museum server"
@@ -510,4 +533,13 @@ fi

# Serve the static web apps in the foreground using our custom nginx config
echo "==> Running NGINX in the foreground with custom configuration"
exec nginx -c /app/data/nginx/ente.conf 
 No newline at end of file
nginx -c /app/data/nginx/ente.conf &
NGINX_PID=$!
echo "==> NGINX started with PID $NGINX_PID"

echo "==> Ente is now running!"
echo "==> Museum server: PID $SERVER_PID"
echo "==> NGINX: PID $NGINX_PID"

# Wait for the processes to finish (or be terminated)
wait 
 No newline at end of file