Files
atabackend/start-services.sh
Beyhan Oğur d50f14bcb1 first commit
2026-04-26 22:20:45 +03:00

99 lines
3.0 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# Django ve Celery servislerini başlatma scripti
# Kullanım: ./start-services.sh
set -e
echo "🚀 Django ve Celery servisleri başlatılıyor..."
# Renk kodları
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# PID dosyaları için dizin
PID_DIR="./pids"
mkdir -p $PID_DIR
# Django PID
DJANGO_PID="$PID_DIR/django.pid"
# Celery Worker PID
CELERY_WORKER_PID="$PID_DIR/celery_worker.pid"
# Cleanup fonksiyonu - Script sonlandığında çağrılır
cleanup() {
echo -e "\n${RED}🛑 Servisler durduruluyor...${NC}"
if [ -f "$DJANGO_PID" ]; then
DJANGO_PID_VALUE=$(cat $DJANGO_PID)
if ps -p $DJANGO_PID_VALUE > /dev/null 2>&1; then
echo -e "${BLUE}Django sunucusu durduruluyor (PID: $DJANGO_PID_VALUE)${NC}"
kill -TERM $DJANGO_PID_VALUE 2>/dev/null || true
fi
rm -f $DJANGO_PID
fi
if [ -f "$CELERY_WORKER_PID" ]; then
CELERY_PID_VALUE=$(cat $CELERY_WORKER_PID)
if ps -p $CELERY_PID_VALUE > /dev/null 2>&1; then
echo -e "${BLUE}Celery worker durduruluyor (PID: $CELERY_PID_VALUE)${NC}"
kill -TERM $CELERY_PID_VALUE 2>/dev/null || true
fi
rm -f $CELERY_WORKER_PID
fi
# Celery process'lerini temizle
pkill -f "celery worker" 2>/dev/null || true
echo -e "${GREEN}✅ Tüm servisler durduruldu${NC}"
exit 0
}
# SIGINT (Ctrl+C) ve SIGTERM sinyallerini yakala
trap cleanup SIGINT SIGTERM
# Eski PID dosyalarını temizle
rm -f $DJANGO_PID $CELERY_WORKER_PID
echo -e "${BLUE}📦 Migrasyonlar kontrol ediliyor...${NC}"
python manage.py migrate --noinput
echo -e "${BLUE}📁 Static dosyalar toplaniyor...${NC}"
python manage.py collectstatic --noinput
echo -e "${GREEN}✅ Hazırlık tamamlandı${NC}\n"
# Django sunucusunu başlat
echo -e "${BLUE}🌐 Django development sunucusu başlatılıyor...${NC}"
python manage.py runserver 0.0.0.0:8000 > ./logs/django.log 2>&1 &
DJANGO_PID_VALUE=$!
echo $DJANGO_PID_VALUE > $DJANGO_PID
echo -e "${GREEN}✅ Django sunucusu başlatıldı (PID: $DJANGO_PID_VALUE)${NC}"
echo -e "${GREEN} URL: http://localhost:8000${NC}\n"
# Celery worker'ı başlat
echo -e "${BLUE}⚙️ Celery worker başlatılıyor...${NC}"
celery -A core worker --loglevel=info > ./logs/celery.log 2>&1 &
CELERY_PID_VALUE=$!
echo $CELERY_PID_VALUE > $CELERY_WORKER_PID
echo -e "${GREEN}✅ Celery worker başlatıldı (PID: $CELERY_PID_VALUE)${NC}\n"
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN}🎉 Tüm servisler başarıyla başlatıldı!${NC}"
echo -e "${GREEN}========================================${NC}"
echo -e "${BLUE}Django Server:${NC} http://localhost:8000"
echo -e "${BLUE}Loglar:${NC}"
echo -e " - Django: ./logs/django.log"
echo -e " - Celery: ./logs/celery.log"
echo -e "\n${RED}Durdurmak için Ctrl+C tuşlarına basın${NC}\n"
# Logları takip et
tail -f ./logs/django.log ./logs/celery.log &
TAIL_PID=$!
# Sonsuz döngü - servisler çalışmaya devam etsin
wait $DJANGO_PID_VALUE $CELERY_PID_VALUE