edit entrypoint
This commit is contained in:
1 parent
aba47ec997
commit
5711ab1a8c
1 file changed
+36
-6
+36
-6
@@ -1,15 +1,45 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# متوقف کردن اسکریپت در صورت بروز هرگونه خطا در مراحل آمادهسازی
|
# ۱. متوقف کردن آنی کل فرآیند کانتینر در صورت بروز خطا در هر لایه
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo "==> Collecting Static Files..."
|
echo "==> [1/4] Collecting Static Files..."
|
||||||
# ۱. انتقال به ابتدای اسکریپت
|
|
||||||
python manage.py collectstatic --noinput --clear
|
python manage.py collectstatic --noinput --clear
|
||||||
|
|
||||||
echo "==> Running Database Migrations..."
|
echo "==> [2/4] Running Database Migrations..."
|
||||||
# ۲. این دستور معمولاً باید بعد از استاتیکفایلها یا در مرحلهای مجزا اجرا شود
|
|
||||||
python manage.py migrate --noinput
|
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
|
exec gunicorn --bind 0.0.0.0:8000 khatibi.wsgi:application
|
||||||
Reference in new issue
Block a user