diff --git a/start.sh b/start.sh index 779dbac..6bc5070 100644 --- a/start.sh +++ b/start.sh @@ -1,14 +1,14 @@ #!/bin/bash # Better signal handling - forward signals to child processes -trap 'kill -TERM $SERVER_PID; kill -TERM $NGINX_PID; exit' TERM INT +trap 'kill -TERM $SERVER_PID; exit' TERM INT set -eu echo "==> Starting Ente Cloudron app..." # Create necessary directories -mkdir -p /app/data/config /app/data/storage /app/data/caddy /app/data/go /app/data/logs +mkdir -p /app/data/config /app/data/storage /app/data/go /app/data/logs # Add comment about Cloudron filesystem limitations echo "==> NOTE: Running in Cloudron environment with limited write access" @@ -211,13 +211,6 @@ sed -i \ sed -i 's|storage.type: "local"|storage.type: "s3"|g' /app/data/config/config.yaml sed -i 's|s3.are_local_buckets: true|s3.are_local_buckets: false|g' /app/data/config/config.yaml -# Install or verify required packages -echo "==> Checking for required packages" -if ! command -v nginx &> /dev/null; then - echo "==> Installing NGINX" - apt-get update && apt-get install -y nginx -fi - # Set up the API endpoint for the web apps API_ENDPOINT="${CLOUDRON_APP_ORIGIN}/api" echo "==> Setting API endpoint to $API_ENDPOINT" @@ -232,388 +225,19 @@ echo "==> Set environment variables for web apps" # Create directory for configuration files mkdir -p /app/data/public mkdir -p /app/data/scripts -mkdir -p /app/data/nginx -mkdir -p /app/data/logs/nginx - -# Create a debugging script -cat > /app/data/public/debug.js <' + - 'process.env.NEXT_PUBLIC_ENTE_ENDPOINT: ' + (window.process?.env?.NEXT_PUBLIC_ENTE_ENDPOINT || 'undefined') + '
' + - 'localStorage ENTE_CONFIG: ' + localStorage.getItem('ENTE_CONFIG') + '
' + - 'localStorage NEXT_PUBLIC_ENTE_ENDPOINT: ' + localStorage.getItem('NEXT_PUBLIC_ENTE_ENDPOINT'); - debugDiv.appendChild(configInfo); - - // Add toggle button - const toggleButton = document.createElement('button'); - toggleButton.innerText = 'Toggle Debug Info'; - toggleButton.style.marginTop = '10px'; - toggleButton.onclick = function() { - configInfo.style.display = configInfo.style.display === 'none' ? 'block' : 'none'; - }; - debugDiv.appendChild(toggleButton); - - // Add to document when it's ready - if (document.body) { - document.body.appendChild(debugDiv); - } else { - window.addEventListener('DOMContentLoaded', function() { - document.body.appendChild(debugDiv); - }); - } -})(); -EOT - -# Create debug info HTML page -cat > /app/data/public/debug.html < - - - - Ente Debug Info - - - -

Ente Debug Information

- -
-

Frontend Configuration

-
Loading...
-
- -
-

URL Test

-

Testing URL construction with API endpoint:

-
Running test...
-
- -
-

API Health Check

-
Checking API health...
-
- - - - -EOT - -# Create a configuration script with properly formatted URL -cat > /app/data/public/config.js < Setting up NGINX server" +mkdir -p /app/data/logs # Define ports -NGINX_PORT=3080 API_PORT=8080 # Check if ports are available echo "==> Checking port availability" -if lsof -i:$NGINX_PORT > /dev/null 2>&1; then - echo "==> WARNING: Port $NGINX_PORT is already in use" -else - echo "==> Port $NGINX_PORT is available for NGINX" -fi - if lsof -i:$API_PORT > /dev/null 2>&1; then echo "==> WARNING: Port $API_PORT is already in use" else echo "==> Port $API_PORT is available for API server" fi -# Create necessary NGINX temp directories -mkdir -p /app/data/nginx/client_body_temp -mkdir -p /app/data/nginx/proxy_temp -mkdir -p /app/data/nginx/fastcgi_temp -mkdir -p /app/data/nginx/uwsgi_temp -mkdir -p /app/data/nginx/scgi_temp -mkdir -p /app/data/logs/nginx - -# Create the NGINX config -cat > /app/data/nginx/nginx.conf <' ''; - sub_filter_once on; - sub_filter_types text/html; - } - - # Accounts app - location /accounts/ { - alias /app/web/accounts/; - try_files \$uri \$uri/ /accounts/index.html; - - # Insert config script for HTML files - sub_filter '' ''; - sub_filter_once on; - sub_filter_types text/html; - } - - # Auth app - location /auth/ { - alias /app/web/auth/; - try_files \$uri \$uri/ /auth/index.html; - - # Insert config script for HTML files - sub_filter '' ''; - sub_filter_once on; - sub_filter_types text/html; - } - - # Cast app - location /cast/ { - alias /app/web/cast/; - try_files \$uri \$uri/ /cast/index.html; - - # Insert config script for HTML files - sub_filter '' ''; - sub_filter_once on; - sub_filter_types text/html; - } - } -} -EOT - -echo "==> Created NGINX config at /app/data/nginx/nginx.conf" - -# Start NGINX -nginx -c /app/data/nginx/nginx.conf -p /app/data/nginx & -NGINX_PID=$! -echo "==> NGINX started with PID $NGINX_PID" - -# Wait for NGINX to start -sleep 2 - -# Test NGINX connectivity -echo "==> Testing NGINX connectivity" -for i in {1..5}; do - if curl -s --max-time 2 --head --fail http://localhost:$NGINX_PORT/health > /dev/null; then - echo "==> NGINX is running properly on port $NGINX_PORT" - break - else - if [ $i -eq 5 ]; then - echo "==> Failed to connect to NGINX after multiple attempts" - echo "==> Last 20 lines of NGINX error log:" - tail -20 /app/data/logs/nginx/error.log || echo "==> No NGINX error log available" - echo "==> Network ports in use:" - netstat -tuln || echo "==> netstat command not available" - else - echo "==> Attempt $i: Waiting for NGINX to start... (1 second)" - sleep 1 - fi - fi -done - # 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) @@ -962,12 +586,10 @@ done echo "==> Application is now running" echo "==> Access your Ente instance at: $CLOUDRON_APP_ORIGIN" -echo "==> To view debug information, visit: $CLOUDRON_APP_ORIGIN/debug" echo "==> Entering wait state - press Ctrl+C to stop" # Wait for all background processes to complete (or for user to interrupt) wait $SERVER_PID -wait $NGINX_PID # Create a new go file to inject into the build that overrides the database connection mkdir -p "$SERVER_DIR/overrides"