#!/bin/sh

# Ensure database and logs directories exist with proper permissions
# We run as root first (before USER directive), fix permissions, then exec to nodejs

set -e

# Create directories if they don't exist
mkdir -p /app/db
mkdir -p /app/logs

# Make directories world-writable to allow the nodejs user to create files
chmod 777 /app/db
chmod 777 /app/logs

# Run the Express server as nodejs user
exec su-exec nodejs node server/index.js
