# Logrotate configuration for Adtlas application logs

# Global options
daily
rotate 7
compress
delaycompress
missingok
notifempty
create 644 root root

# Include additional configurations
include /etc/logrotate.d

# Application logs
/var/log/app/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 644 root root
    postrotate
        # Send signal to applications to reopen log files if needed
        /bin/kill -USR1 $(cat /var/run/app.pid 2>/dev/null) 2>/dev/null || true
    endscript
}

# Django application logs
/var/log/app/django/*.log {
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    create 644 root root
    copytruncate
}

# Celery logs
/var/log/app/celery/*.log {
    daily
    rotate 14
    compress
    delaycompress
    missingok
    notifempty
    create 644 root root
    copytruncate
}

# Nginx access logs
/var/log/nginx/access.log {
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    create 644 nginx nginx
    postrotate
        /bin/kill -USR1 $(cat /var/run/nginx.pid 2>/dev/null) 2>/dev/null || true
    endscript
}

# Nginx error logs
/var/log/nginx/error.log {
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
    create 644 nginx nginx
    postrotate
        /bin/kill -USR1 $(cat /var/run/nginx.pid 2>/dev/null) 2>/dev/null || true
    endscript
}