Enhance start.sh with improved server directory detection and debugging
This commit is contained in:
parent
1fc7bcac62
commit
fb0d4fd34f
47
start.sh
47
start.sh
@ -5,6 +5,12 @@ set -eu
|
|||||||
# Create necessary directories
|
# Create necessary directories
|
||||||
mkdir -p /app/data/config /app/data/storage
|
mkdir -p /app/data/config /app/data/storage
|
||||||
|
|
||||||
|
# Print debug information about repository structure
|
||||||
|
echo "==> DEBUG: Repository structure at /app/code"
|
||||||
|
find /app/code -type d -not -path "*/node_modules/*" -not -path "*/\.*" | sort
|
||||||
|
echo "==> DEBUG: All package.json files in repository"
|
||||||
|
find /app/code -name "package.json" -not -path "*/node_modules/*" | sort
|
||||||
|
|
||||||
# Create config template file on first run
|
# Create config template file on first run
|
||||||
if [[ ! -f /app/data/config/config.yaml ]]; then
|
if [[ ! -f /app/data/config/config.yaml ]]; then
|
||||||
echo "==> First run - creating configuration template"
|
echo "==> First run - creating configuration template"
|
||||||
@ -85,6 +91,9 @@ sed -i \
|
|||||||
|
|
||||||
# Find the correct server directory
|
# Find the correct server directory
|
||||||
SERVER_DIR=""
|
SERVER_DIR=""
|
||||||
|
|
||||||
|
# More thorough search for server directory
|
||||||
|
# Try specific paths first
|
||||||
for dir in "/app/code/server" "/app/code/packages/server"; do
|
for dir in "/app/code/server" "/app/code/packages/server"; do
|
||||||
if [ -f "$dir/package.json" ]; then
|
if [ -f "$dir/package.json" ]; then
|
||||||
SERVER_DIR="$dir"
|
SERVER_DIR="$dir"
|
||||||
@ -92,6 +101,21 @@ for dir in "/app/code/server" "/app/code/packages/server"; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# If not found, search for any directory containing package.json with "server" in its path
|
||||||
|
if [ -z "$SERVER_DIR" ]; then
|
||||||
|
SERVER_CANDIDATES=$(find /app/code -name "package.json" -not -path "*/node_modules/*" -path "*/server*" | sort)
|
||||||
|
if [ -n "$SERVER_CANDIDATES" ]; then
|
||||||
|
FIRST_CANDIDATE=$(echo "$SERVER_CANDIDATES" | head -n 1)
|
||||||
|
SERVER_DIR=$(dirname "$FIRST_CANDIDATE")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Last resort - look for package.json in the monorepo root
|
||||||
|
if [ -z "$SERVER_DIR" ] && [ -f "/app/code/package.json" ]; then
|
||||||
|
echo "==> Using root package.json as server directory"
|
||||||
|
SERVER_DIR="/app/code"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$SERVER_DIR" ]; then
|
if [ -z "$SERVER_DIR" ]; then
|
||||||
echo "==> ERROR: Could not find server directory with package.json"
|
echo "==> ERROR: Could not find server directory with package.json"
|
||||||
echo " Server directory structure may have changed."
|
echo " Server directory structure may have changed."
|
||||||
@ -100,6 +124,10 @@ if [ -z "$SERVER_DIR" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "==> Found server directory at $SERVER_DIR"
|
echo "==> Found server directory at $SERVER_DIR"
|
||||||
|
echo "==> Contents of $SERVER_DIR:"
|
||||||
|
ls -la "$SERVER_DIR"
|
||||||
|
echo "==> Contents of package.json:"
|
||||||
|
cat "$SERVER_DIR/package.json"
|
||||||
|
|
||||||
# Change to server directory
|
# Change to server directory
|
||||||
cd "$SERVER_DIR"
|
cd "$SERVER_DIR"
|
||||||
@ -114,15 +142,26 @@ else
|
|||||||
echo "==> Skipping database migrations (script not found)"
|
echo "==> Skipping database migrations (script not found)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check for alternative start scripts if "serve" doesn't exist
|
||||||
|
SERVE_SCRIPT=""
|
||||||
|
for script in "serve" "start" "dev" "server"; do
|
||||||
|
if grep -q "\"$script\"" package.json; then
|
||||||
|
SERVE_SCRIPT="$script"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Change ownership to cloudron user
|
# Change ownership to cloudron user
|
||||||
chown -R cloudron:cloudron /app/data
|
chown -R cloudron:cloudron /app/data
|
||||||
|
|
||||||
# Start the server
|
# Start the server
|
||||||
echo "==> Starting Ente server"
|
if [ -n "$SERVE_SCRIPT" ]; then
|
||||||
if grep -q "\"serve\"" package.json; then
|
echo "==> Starting Ente server with script: $SERVE_SCRIPT"
|
||||||
exec /usr/local/bin/gosu cloudron:cloudron NODE_ENV=production CONFIG_PATH=/app/data/config/config.yaml yarn run serve
|
exec /usr/local/bin/gosu cloudron:cloudron NODE_ENV=production CONFIG_PATH=/app/data/config/config.yaml yarn run "$SERVE_SCRIPT"
|
||||||
else
|
else
|
||||||
echo "==> ERROR: Could not find 'serve' script in package.json"
|
echo "==> ERROR: Could not find any server script in package.json"
|
||||||
|
echo " Available scripts:"
|
||||||
|
grep -o '"[^"]*"\s*:\s*"[^"]*"' package.json | grep -o '"[^"]*"' | head -n 1 | tr -d '"'
|
||||||
echo " Please check the ente repository structure."
|
echo " Please check the ente repository structure."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
Loading…
x
Reference in New Issue
Block a user