#!/bin/sh
set -e

# The application source is bind-mounted from the host, so its ownership is
# whatever the host uses (often root). php-fpm workers run as www-data and must
# be able to write Laravel's runtime directories. Fix that here, at container
# start, after the bind mount is in place (a build-time chown cannot affect a
# bind-mounted path). Runs for app, horizon, and scheduler containers alike.
mkdir -p \
    storage/framework/views \
    storage/framework/cache/data \
    storage/framework/sessions \
    storage/logs \
    bootstrap/cache

chown -R www-data:www-data storage bootstrap/cache 2>/dev/null || true
chmod -R ug+rwX storage bootstrap/cache 2>/dev/null || true

exec "$@"
