File tree Expand file tree Collapse file tree 3 files changed +48
-4
lines changed
backend/src/infrastructure/database/scripts Expand file tree Collapse file tree 3 files changed +48
-4
lines changed Original file line number Diff line number Diff line change 1+ import { sql } from 'drizzle-orm'
2+ import { getDB } from './db'
3+
4+ async function checkConnection ( ) {
5+ try {
6+ const db = await getDB ( )
7+ await db . execute ( sql `SELECT 1` )
8+ console . log ( 'Database is ready and accepting queries!' )
9+ process . exit ( 0 )
10+ } catch ( error : any ) {
11+ console . error ( `Database check failed: ${ error . message } ` )
12+ process . exit ( 1 )
13+ }
14+ }
15+
16+ checkConnection ( )
Original file line number Diff line number Diff line change 33
44: " ${PUID:? PUID is not defined} "
55: " ${PGID:? PGID is not defined} "
6+ : " ${FORCE_PERMISSIONS:= false} "
67
78# Create syncin group if needed
89group_name=$( getent group " ${PGID} " | cut -d: -f1)
@@ -24,9 +25,11 @@ chown "${PUID}:${PGID}" /app
2425CURRENT_UID=$( stat -c ' %u' /app/data)
2526CURRENT_GID=$( stat -c ' %g' /app/data)
2627
27- if [ " ${CURRENT_UID} " != " ${PUID} " ] || [ " ${CURRENT_GID} " != " ${PGID} " ]; then
28+ if [ " ${CURRENT_UID} " != " ${PUID} " ] || [ " ${CURRENT_GID} " != " ${PGID} " ] || [ " ${FORCE_PERMISSIONS} " = " true " ] ; then
2829 chown -R " ${PUID} :${PGID} " /app/data
2930fi
3031
32+ umask 027
33+
3134# Launch server as syncin user
3235exec su-exec " ${PUID} :${PGID} " " $@ "
Original file line number Diff line number Diff line change 22
33if [ " ${SKIP_INIT} " != " true" ]; then
44 if [ ! -f .init ]; then
5- # wait for database
6- sleep 8
5+ echo " Waiting for database to be ready..."
6+ MAX_RETRIES=30
7+ COUNT=0
8+ CONNECTED=false
9+
10+ while [ $COUNT -lt $MAX_RETRIES ]; do
11+ COUNT=$(( COUNT+ 1 ))
12+ echo " Database connection attempt ${COUNT} /${MAX_RETRIES} ..."
13+ if OUTPUT=$( node server/infrastructure/database/scripts/check-db.js 2>&1 ) ; then
14+ CONNECTED=true
15+ break
16+ fi
17+ sleep 1
18+ done
19+
20+ if [ " $CONNECTED " = " false" ]; then
21+ echo " Error: Timeout waiting for database after ${MAX_RETRIES} attempts:"
22+ echo " $OUTPUT "
23+ exit 1
24+ fi
25+
726 # migrate database
827 if ! npx drizzle-kit migrate --config=server/infrastructure/database/configuration.js; then
928 echo " Error: unable to migrate database schema !" >&2
@@ -19,9 +38,15 @@ if [ "${SKIP_INIT}" != "true" ]; then
1938 fi
2039 fi
2140 touch .init
22- chmod -R 755 /app/data
41+ chmod 750 /app/data
2342 fi
2443else
2544 echo " SKIP_INIT invoked"
2645fi
46+
47+ if [ " ${FORCE_PERMISSIONS} " = " true" ]; then
48+ echo " FORCE_PERMISSIONS: Applying recursive permissions (Dirs: 750, Files: 640)..."
49+ chmod -R u=rwX,g=rX,o= /app/data
50+ fi
51+
2752exec node server/main.js
You can’t perform that action at this time.
0 commit comments