Improve start.sh with Cloudron best practices
This commit is contained in:
parent
789d7028b9
commit
d8a40880d8
46
start.sh
46
start.sh
@ -1,9 +1,22 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Better signal handling - forward signals to child processes
|
||||||
|
trap 'kill -TERM $SERVER_PID; kill -TERM $NGINX_PID; exit' TERM INT
|
||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
echo "==> Starting Ente Cloudron app..."
|
||||||
|
|
||||||
# Create necessary directories
|
# 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"
|
echo "==> DEBUG: Full repository structure at /app/code"
|
||||||
find /app/code -type d -maxdepth 3 -not -path "*/node_modules/*" -not -path "*/\.*" | sort
|
find /app/code -type d -maxdepth 3 -not -path "*/node_modules/*" -not -path "*/\.*" | sort
|
||||||
@ -28,7 +41,6 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Create config template file on first run
|
# Create config template file on first run
|
||||||
if [[ ! -f /app/data/config/config.yaml ]]; then
|
|
||||||
echo "==> First run - creating configuration template"
|
echo "==> First run - creating configuration template"
|
||||||
|
|
||||||
# Generate random secrets
|
# Generate random secrets
|
||||||
@ -97,6 +109,10 @@ S3_SECRET_KEY=aPdHB4fkvQAuJUqPhneoIDcHEHee9cvP2j0nKSly
|
|||||||
S3_PREFIX=ente/
|
S3_PREFIX=ente/
|
||||||
EOT
|
EOT
|
||||||
echo "==> Test S3 configuration created for Wasabi"
|
echo "==> Test S3 configuration created for Wasabi"
|
||||||
|
|
||||||
|
# Mark initialization as complete
|
||||||
|
touch /app/data/.initialized
|
||||||
|
echo "==> Initialization complete"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if s3.env exists
|
# Check if s3.env exists
|
||||||
@ -342,6 +358,16 @@ export ENTE_LOG_LEVEL=debug
|
|||||||
echo "==> Testing API connectivity"
|
echo "==> Testing API connectivity"
|
||||||
curl -v http://localhost:8000/api/health || echo "API not yet available, this is normal during startup"
|
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
|
# Set up database environment variables and ensure proper SSL config
|
||||||
export ENTE_DB_USER="${CLOUDRON_POSTGRESQL_USERNAME}"
|
export ENTE_DB_USER="${CLOUDRON_POSTGRESQL_USERNAME}"
|
||||||
export ENTE_DB_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
|
export ENTE_DB_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
|
||||||
@ -361,10 +387,7 @@ export REMOTE_STORAGE_PREFIX="${S3_PREFIX:-ente/}"
|
|||||||
|
|
||||||
# Change ownership to cloudron user
|
# Change ownership to cloudron user
|
||||||
chown -R cloudron:cloudron /app/data
|
chown -R cloudron:cloudron /app/data
|
||||||
|
chown -R cloudron:cloudron /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"
|
|
||||||
|
|
||||||
# Start Museum server on port 8000 (different from the NGINX port 8080)
|
# Start Museum server on port 8000 (different from the NGINX port 8080)
|
||||||
echo "==> Starting Museum server"
|
echo "==> Starting Museum server"
|
||||||
@ -510,4 +533,13 @@ fi
|
|||||||
|
|
||||||
# Serve the static web apps in the foreground using our custom nginx config
|
# Serve the static web apps in the foreground using our custom nginx config
|
||||||
echo "==> Running NGINX in the foreground with custom configuration"
|
echo "==> Running NGINX in the foreground with custom configuration"
|
||||||
exec nginx -c /app/data/nginx/ente.conf
|
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
|
Loading…
x
Reference in New Issue
Block a user