Spaces:
Paused
Paused
fix: bootstrap-ceo after Paperclip init, better startup error messages
Browse files- Start Paperclip in background, wait for config.json + /api/health (max 90s)
- Run bootstrap-ceo after server is ready (config exists), not before
- Print boxed admin invite URL to logs when bootstrap generates one
- Proxy shows "starting up" message instead of generic error during boot
- Cleanup handler now kills PAPERCLIP_PID on SIGTERM
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Files changed (2)
- health-server.js+2-1
- start.sh+38-13
196 unmodified lines197198199200201202203204196 unmodified linesres.status(response.statusCode).send(response.body);} catch (error) {res.status(503).json({error: "Paperclip service unavailable",details: error.message,});}196 unmodified lines197198199200201202203204205196 unmodified linesres.status(response.statusCode).send(response.body);} catch (error) {const starting = error.message && error.message.includes("ECONNREFUSED");res.status(503).json({error: starting ? "Paperclip starting up, please wait..." : "Paperclip service unavailable",details: error.message,});}
242 unmodified lines2432442452462472481 unmodified line250251252253254255256257258259260261262263264265266267268242 unmodified linesecho "Stopping services..."[ -n "$HEALTH_PID" ] && kill $HEALTH_PID 2>/dev/null || true[ -n "$SYNC_PID" ] && kill $SYNC_PID 2>/dev/null || trueecho -e "${GREEN}Shutdown complete${NC}"exit 01 unmodified linetrap cleanup SIGTERM SIGINT# Generate first admin invite URL if no admin exists yet# Runs against the database directly (no server needed) and prints the URL to logsecho -e "${BLUE}[8/8] Bootstrapping admin account...${NC}"BOOTSTRAP_OUTPUT=$(pnpm paperclipai auth bootstrap-ceo 2>&1)if echo "$BOOTSTRAP_OUTPUT" | grep -qi "invite\|http\|url\|link"; thenecho -e "${GREEN}β Admin invite URL:${NC}"echo "$BOOTSTRAP_OUTPUT"echo -e "${YELLOW}Copy the URL above to complete first-time setup.${NC}\n"elif echo "$BOOTSTRAP_OUTPUT" | grep -qi "already\|exists\|skip"; thenecho -e "${GREEN}β Admin account already exists${NC}\n"elseecho -e "${YELLOW}Bootstrap output: ${BOOTSTRAP_OUTPUT}${NC}\n"fi# Start Paperclip server with tsx loader (loads workspace .ts packages at runtime)exec node --import ./server/node_modules/tsx/dist/loader.mjs server/dist/index.js242 unmodified lines2432442452462472482491 unmodified line251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293242 unmodified linesecho "Stopping services..."[ -n "$HEALTH_PID" ] && kill $HEALTH_PID 2>/dev/null || true[ -n "$SYNC_PID" ] && kill $SYNC_PID 2>/dev/null || true[ -n "$PAPERCLIP_PID" ] && kill $PAPERCLIP_PID 2>/dev/null || trueecho -e "${GREEN}Shutdown complete${NC}"exit 01 unmodified linetrap cleanup SIGTERM SIGINT# ============================================================================# 8. Start Paperclip, wait for init, then bootstrap admin# ============================================================================echo -e "${BLUE}[8/8] Starting Paperclip server...${NC}"# Start Paperclip in background so we can run post-init stepsnode --import ./server/node_modules/tsx/dist/loader.mjs server/dist/index.js &PAPERCLIP_PID=$!# Wait for Paperclip to create config.json and health endpoint to respond (max 90s)CONFIG_FILE="/paperclip/instances/default/config.json"echo "Waiting for Paperclip to initialize..."for i in $(seq 1 45); doif [ -f "$CONFIG_FILE" ] && curl -sf http://localhost:3100/api/health >/dev/null 2>&1; thenecho -e "${GREEN}β Paperclip ready (${i}s)${NC}"breakfisleep 2done# Bootstrap first admin β generates invite URL (only works if no admin exists)if [ -f "$CONFIG_FILE" ]; thenecho -e "${BLUE}Bootstrapping admin account...${NC}"BOOTSTRAP_OUTPUT=$(pnpm paperclipai auth bootstrap-ceo 2>&1 || true)if echo "$BOOTSTRAP_OUTPUT" | grep -q "http"; thenINVITE_URL=$(echo "$BOOTSTRAP_OUTPUT" | grep -o 'https\?://[^ ]*' | head -1)echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"echo -e "${GREEN}β ADMIN SETUP URL (open in browser): β${NC}"echo -e "${GREEN}β ${INVITE_URL}${NC}"echo -e "${GREEN}ββββββββββββββββββββββββββββββββββββββββββββββββ${NC}"else# Already configured or no output β not an errorecho -e "${GREEN}β Admin account ready${NC}"fielseecho -e "${YELLOW}Warning: Paperclip config not found, skipping admin bootstrap${NC}"fi# Keep container alive β wait for Paperclip process to exitwait $PAPERCLIP_PID
health-server.js+2-1
start.sh+38-13