From 5711ab1a8c2254f59208e5f59b9099ef9a932d7b Mon Sep 17 00:00:00 2001 From: javad Date: Tue, 23 Jun 2026 23:54:42 +0330 Subject: [PATCH] edit entrypoint --- entrypoint.sh | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index c421dbb..50539f5 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,15 +1,45 @@ #!/bin/sh -# متوقف کردن اسکریپت در صورت بروز هرگونه خطا در مراحل آماده‌سازی +# ۱. متوقف کردن آنی کل فرآیند کانتینر در صورت بروز خطا در هر لایه set -e -echo "==> Collecting Static Files..." -# ۱. انتقال به ابتدای اسکریپت +echo "==> [1/4] Collecting Static Files..." python manage.py collectstatic --noinput --clear -echo "==> Running Database Migrations..." -# ۲. این دستور معمولاً باید بعد از استاتیک‌فایل‌ها یا در مرحله‌ای مجزا اجرا شود +echo "==> [2/4] Running Database Migrations..." python manage.py migrate --noinput -echo "==> Starting Gunicorn..." +echo "==> [3/4] Optimizing SQLite Storage (WAL & Synchronous)..." +# استفاده از بلاک EOF پایتون برای خوانایی، ایزولاسیون خطا و ثبت سیستماتیک لاگ‌ها +python << 'EOF' +import sqlite3 +import sys + +db_path = '/app/sqlite/db.sqlite3' +try: + conn = sqlite3.connect(db_path, timeout=30) + cursor = conn.cursor() + + # فعال‌سازی و تایید صحت حالت WAL + cursor.execute('PRAGMA journal_mode=WAL;') + journal_mode = cursor.fetchone()[0] + + cursor.execute('PRAGMA synchronous=FULL;') + cursor.execute('PRAGMA synchronous;') + sync_mode = cursor.fetchone()[0] + + conn.close() + + print(f"SUCCESS: Infrastructure Database Configured -> Journal: {journal_mode.upper()} | Sync: {sync_mode}") + +except sqlite3.OperationalError as e: + print(f"CRITICAL: Database is locked or inaccessible: {str(e)}", file=sys.stderr) + sys.exit(1) # بازگرداندن وضعیت خطا به داکر برای جلوگیری از بالا آمدن وب‌سرور معیوب +except Exception as e: + print(f"CRITICAL: Failed to apply enterprise database optimization: {str(e)}", file=sys.stderr) + sys.exit(1) +EOF + +echo "==> [4/4] Starting Gunicorn Web Server..." +# جایگزین کردن پروسس PID 1 با Gunicorn برای مدیریت اصولی سیگنال‌های توقف داکر (Graceful Shutdown) exec gunicorn --bind 0.0.0.0:8000 khatibi.wsgi:application \ No newline at end of file