#!/bin/sh set -eu if [ "$(id -u)" = "0" ]; then mkdir -p \ storage/app/public \ storage/app/temp \ storage/app/uploads \ storage/framework/cache/data \ storage/framework/sessions \ storage/framework/views \ storage/logs \ bootstrap/cache # 修复旧容器或 root CLI 遗留的属主;之后所有 Artisan 命令都降权执行, # 避免再次产生网页进程无法写入的缓存、日志和备份文件。 chown -R www-data:www-data storage bootstrap/cache if [ -f .env ]; then chown www-data:www-data .env chmod 660 .env fi fi assert_web_writable() { runuser -u www-data -- test -w storage/app runuser -u www-data -- test -w storage/framework/views runuser -u www-data -- test -w storage/logs runuser -u www-data -- test -w bootstrap/cache if [ -f .env ]; then runuser -u www-data -- test -w .env fi } run_artisan_as_web() { runuser -u www-data -- php artisan "$@" } app_environment="" if [ -f .env ]; then app_environment="$(sed -n 's/^APP_ENV=//p' .env | tail -n 1 | tr -d '\r' | sed 's/^"//; s/"$//; s/^'\''//; s/'\''$//')" fi if [ "${1:-}" = "apache2-foreground" ]; then sed -ri 's/^Listen 80$/Listen 18088/' /etc/apache2/ports.conf assert_web_writable run_artisan_as_web optimize:clear run_artisan_as_web package:discover --ansi if grep -Eq '^APP_INSTALLED=(true|1)$' .env; then # 开发机的临时引导库属于可恢复的本机数据,拉取新代码后自动补齐 # 结构;命令会在共享系统数据库模式下直接跳过,绝不由开发机迁移 # 团队共享数据库。 run_artisan_as_web local-bootstrap:update --no-ansi if [ "${RUN_MIGRATIONS:-0}" = "1" ]; then run_artisan_as_web migrate --force fi if [ "$app_environment" = "local" ]; then # Keep development source live: optimize:clear above removes any # stale bootstrap/view artifacts, while view.cache=false makes # Blade recompile templates on every request without a restart. run_artisan_as_web optimize:clear else # Production keeps the existing immutable config and compiled # Blade caches for startup and request performance. run_artisan_as_web config:cache run_artisan_as_web view:cache fi fi fi exec "$@"