fix(render): add comprehensive error handling and logging
- Disable set -e during permission testing - Add explicit error checks with clear messages - Verify token is set before starting - Add directory listings if dist/index.js missing - More verbose logging throughout - Check return codes explicitly
This commit is contained in:
parent
aa0621ae38
commit
173f6d33c0
@ -1,17 +1,19 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Render startup script - creates config and starts gateway
|
# Render startup script - creates config and starts gateway
|
||||||
set -e
|
# Don't use set -e initially - we'll enable it after setup
|
||||||
|
|
||||||
echo "=== Render startup script ==="
|
echo "=== Render startup script ==="
|
||||||
echo "HOME=${HOME:-not set}"
|
echo "HOME=${HOME:-not set}"
|
||||||
echo "CLAWDBOT_STATE_DIR=${CLAWDBOT_STATE_DIR:-not set}"
|
echo "CLAWDBOT_STATE_DIR=${CLAWDBOT_STATE_DIR:-not set}"
|
||||||
echo "User: $(whoami 2>/dev/null || echo unknown)"
|
echo "User: $(whoami 2>/dev/null || echo unknown)"
|
||||||
echo "UID: $(id -u 2>/dev/null || echo unknown)"
|
echo "UID: $(id -u 2>/dev/null || echo unknown)"
|
||||||
|
echo "PWD: $(pwd)"
|
||||||
|
|
||||||
# Set HOME if not set (node user's home is /home/node)
|
# Set HOME if not set (node user's home is /home/node)
|
||||||
if [ -z "${HOME}" ]; then
|
if [ -z "${HOME}" ]; then
|
||||||
export HOME="/home/node"
|
if [ -d "/home/node" ]; then
|
||||||
if [ ! -d "${HOME}" ]; then
|
export HOME="/home/node"
|
||||||
|
else
|
||||||
export HOME="/tmp"
|
export HOME="/tmp"
|
||||||
fi
|
fi
|
||||||
echo "Set HOME to: ${HOME}"
|
echo "Set HOME to: ${HOME}"
|
||||||
@ -20,14 +22,18 @@ fi
|
|||||||
# Use CLAWDBOT_STATE_DIR if set and writable, otherwise use HOME/.clawdbot
|
# Use CLAWDBOT_STATE_DIR if set and writable, otherwise use HOME/.clawdbot
|
||||||
CONFIG_DIR="${HOME}/.clawdbot"
|
CONFIG_DIR="${HOME}/.clawdbot"
|
||||||
if [ -n "${CLAWDBOT_STATE_DIR}" ]; then
|
if [ -n "${CLAWDBOT_STATE_DIR}" ]; then
|
||||||
# Test if we can write to it
|
# Test if we can write to it (disable exit on error for this test)
|
||||||
if mkdir -p "${CLAWDBOT_STATE_DIR}" 2>/dev/null && touch "${CLAWDBOT_STATE_DIR}/.test" 2>/dev/null; then
|
set +e
|
||||||
|
mkdir -p "${CLAWDBOT_STATE_DIR}" 2>/dev/null
|
||||||
|
touch "${CLAWDBOT_STATE_DIR}/.test" 2>/dev/null
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
rm -f "${CLAWDBOT_STATE_DIR}/.test" 2>/dev/null
|
rm -f "${CLAWDBOT_STATE_DIR}/.test" 2>/dev/null
|
||||||
CONFIG_DIR="${CLAWDBOT_STATE_DIR}"
|
CONFIG_DIR="${CLAWDBOT_STATE_DIR}"
|
||||||
echo "Using CLAWDBOT_STATE_DIR: ${CONFIG_DIR}"
|
echo "Using CLAWDBOT_STATE_DIR: ${CONFIG_DIR}"
|
||||||
else
|
else
|
||||||
echo "Warning: ${CLAWDBOT_STATE_DIR} not writable, using ${CONFIG_DIR}"
|
echo "Warning: ${CLAWDBOT_STATE_DIR} not writable, using ${CONFIG_DIR}"
|
||||||
fi
|
fi
|
||||||
|
set -e
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CONFIG_FILE="${CONFIG_DIR}/clawdbot.json"
|
CONFIG_FILE="${CONFIG_DIR}/clawdbot.json"
|
||||||
@ -35,11 +41,14 @@ CONFIG_FILE="${CONFIG_DIR}/clawdbot.json"
|
|||||||
echo "Config dir: ${CONFIG_DIR}"
|
echo "Config dir: ${CONFIG_DIR}"
|
||||||
echo "Config file: ${CONFIG_FILE}"
|
echo "Config file: ${CONFIG_FILE}"
|
||||||
|
|
||||||
# Create config directory
|
# Create config directory (this should always work for HOME/.clawdbot)
|
||||||
mkdir -p "${CONFIG_DIR}"
|
if ! mkdir -p "${CONFIG_DIR}" 2>/dev/null; then
|
||||||
|
echo "ERROR: Failed to create config directory: ${CONFIG_DIR}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Write config file
|
# Write config file
|
||||||
cat > "${CONFIG_FILE}" << 'EOF'
|
if ! cat > "${CONFIG_FILE}" << 'EOF'
|
||||||
{
|
{
|
||||||
"gateway": {
|
"gateway": {
|
||||||
"mode": "local",
|
"mode": "local",
|
||||||
@ -50,9 +59,19 @@ cat > "${CONFIG_FILE}" << 'EOF'
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
then
|
||||||
|
echo "ERROR: Failed to write config file: ${CONFIG_FILE}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
echo "=== Config written to ${CONFIG_FILE} ==="
|
echo "=== Config written to ${CONFIG_FILE} ==="
|
||||||
cat "${CONFIG_FILE}"
|
cat "${CONFIG_FILE}" || echo "Warning: Could not read config file"
|
||||||
|
|
||||||
|
# Verify config file exists and is readable
|
||||||
|
if [ ! -f "${CONFIG_FILE}" ]; then
|
||||||
|
echo "ERROR: Config file does not exist: ${CONFIG_FILE}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Set environment variables for gateway
|
# Set environment variables for gateway
|
||||||
export CLAWDBOT_STATE_DIR="${CONFIG_DIR}"
|
export CLAWDBOT_STATE_DIR="${CONFIG_DIR}"
|
||||||
@ -66,16 +85,37 @@ echo "CLAWDBOT_CONFIG_PATH=${CLAWDBOT_CONFIG_PATH}"
|
|||||||
# Verify node is available
|
# Verify node is available
|
||||||
if ! command -v node >/dev/null 2>&1; then
|
if ! command -v node >/dev/null 2>&1; then
|
||||||
echo "ERROR: node command not found"
|
echo "ERROR: node command not found"
|
||||||
|
echo "PATH: ${PATH}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Node version: $(node --version)"
|
||||||
|
|
||||||
# Verify dist/index.js exists
|
# Verify dist/index.js exists
|
||||||
if [ ! -f "dist/index.js" ]; then
|
if [ ! -f "dist/index.js" ]; then
|
||||||
echo "ERROR: dist/index.js not found"
|
echo "ERROR: dist/index.js not found"
|
||||||
|
echo "Contents of /app:"
|
||||||
|
ls -la /app 2>/dev/null || echo "Cannot list /app"
|
||||||
|
echo "Contents of current directory:"
|
||||||
|
ls -la . 2>/dev/null || echo "Cannot list current directory"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Found dist/index.js"
|
||||||
|
|
||||||
|
# Check if token is set
|
||||||
|
if [ -z "${CLAWDBOT_GATEWAY_TOKEN}" ]; then
|
||||||
|
echo "ERROR: CLAWDBOT_GATEWAY_TOKEN is not set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Token is set (length: ${#CLAWDBOT_GATEWAY_TOKEN})"
|
||||||
|
|
||||||
|
# Enable strict error handling for the final exec
|
||||||
|
set -e
|
||||||
|
|
||||||
# Start gateway
|
# Start gateway
|
||||||
|
echo "Executing: node dist/index.js gateway --port 8080 --bind lan --auth token --allow-unconfigured"
|
||||||
exec node dist/index.js gateway \
|
exec node dist/index.js gateway \
|
||||||
--port 8080 \
|
--port 8080 \
|
||||||
--bind lan \
|
--bind lan \
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user