Files
drone-detector/server/docker-entrypoint.sh
2025-09-21 09:03:09 +02:00

35 lines
1.1 KiB
Bash

#!/bin/sh
# This script runs as root to set up permissions, then switches to nodejs user
# Ensure uploads directory exists and has correct permissions
mkdir -p /app/uploads/logos
chown -R nodejs:nodejs /app/uploads
chmod -R 755 /app/uploads
# Wait for database to be ready
echo "Waiting for database to be ready..."
while ! nc -z postgres 5432; do
echo "Database not ready, waiting..."
sleep 1
done
echo "Database is ready!"
# Check if this is a fresh database by looking for the devices table
echo "Checking database state..."
# Always run database setup (includes migrations + seeding if needed)
echo "Running database setup and migrations..."
su-exec nodejs npm run db:setup
# Check if setup/migrations were successful
if [ $? -eq 0 ]; then
echo "Database initialization completed successfully"
# Set flag to indicate database is already initialized
export DB_INITIALIZED=true
else
echo "Database initialization failed"
exit 1
fi
# Switch to nodejs user and execute the command with dumb-init for signal handling
exec su-exec nodejs dumb-init -- "$@"