Initial commit: homelab configuration and documentation
This commit is contained in:
87
scripts/setup_log_rotation.sh
Executable file
87
scripts/setup_log_rotation.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
# setup_log_rotation.sh - Configure log rotation for homelab services
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
echo "Configuring log rotation for homelab services..."
|
||||
|
||||
# Docker logs
|
||||
cat > /etc/logrotate.d/docker-containers << 'EOF'
|
||||
/var/lib/docker/containers/*/*.log {
|
||||
rotate 7
|
||||
daily
|
||||
compress
|
||||
size=10M
|
||||
missingok
|
||||
delaycompress
|
||||
copytruncate
|
||||
}
|
||||
EOF
|
||||
|
||||
# Traefik logs
|
||||
cat > /etc/logrotate.d/traefik << 'EOF'
|
||||
/var/log/traefik/*.log {
|
||||
rotate 14
|
||||
daily
|
||||
compress
|
||||
missingok
|
||||
delaycompress
|
||||
postrotate
|
||||
docker service update --force traefik_traefik > /dev/null 2>&1 || true
|
||||
endscript
|
||||
}
|
||||
EOF
|
||||
|
||||
# fail2ban logs
|
||||
cat > /etc/logrotate.d/fail2ban-custom << 'EOF'
|
||||
/var/log/fail2ban.log {
|
||||
rotate 30
|
||||
daily
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
postrotate
|
||||
systemctl reload fail2ban > /dev/null 2>&1 || true
|
||||
endscript
|
||||
}
|
||||
EOF
|
||||
|
||||
# Restic backup logs
|
||||
cat > /etc/logrotate.d/restic-backup << 'EOF'
|
||||
/var/log/restic_backup.log {
|
||||
rotate 30
|
||||
daily
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
}
|
||||
EOF
|
||||
|
||||
# Caddy logs
|
||||
cat > /etc/logrotate.d/caddy << 'EOF'
|
||||
/var/log/caddy/*.log {
|
||||
rotate 7
|
||||
daily
|
||||
compress
|
||||
missingok
|
||||
delaycompress
|
||||
}
|
||||
EOF
|
||||
|
||||
# Home lab deployment logs
|
||||
cat > /etc/logrotate.d/homelab << 'EOF'
|
||||
/var/log/homelab_deployment.log {
|
||||
rotate 90
|
||||
daily
|
||||
compress
|
||||
missingok
|
||||
notifempty
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "Testing logrotate configuration..."
|
||||
logrotate -d /etc/logrotate.d/docker-containers
|
||||
|
||||
echo "Log rotation configured successfully."
|
||||
echo "Logs will be rotated daily and compressed."
|
||||
echo "Configuration files created in /etc/logrotate.d/"
|
||||
Reference in New Issue
Block a user