bashbeginner
Logrotate Configuration for Applications
Logrotate config for application logs with daily rotation, compression, and post-rotate hooks.
bashPress ⌘/Ctrl + Shift + C to copy
# /etc/logrotate.d/webapp
/var/log/webapp/*.log {
daily
missingok
rotate 14
compress
delaycompress
notifempty
create 0640 webapp webapp
sharedscripts
postrotate
systemctl reload webapp 2>/dev/null || true
endscript
}
# /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
missingok
rotate 30
compress
delaycompress
notifempty
create 0640 www-data adm
sharedscripts
postrotate
[ -f /var/run/nginx.pid ] && kill -USR1 $(cat /var/run/nginx.pid)
endscript
}
# Test configuration
# sudo logrotate -d /etc/logrotate.d/webapp
# Force rotation
# sudo logrotate -f /etc/logrotate.d/webappUse Cases
- Preventing disk space exhaustion from logs
- Maintaining log history with compression
- Graceful log rotation for running services
Tags
Related Snippets
Similar patterns you can reuse in the same workflow.
bashintermediate
Systemd Service File for Node.js
Systemd unit file to run a Node.js app as a managed service with auto-restart and logging.
Best for: Running production services on Linux servers
#systemd#linux
bashbeginner
Linux Cron Job Setup Examples
Common crontab entries for database backups, log cleanup, health checks, and certificate renewal.
Best for: Automated database backups
#cron#linux
bashintermediate
Log Rotation Management Script
Automate log rotation with compression, retention policies, and disk space monitoring in Bash.
Best for: Preventing disk space exhaustion from logs
#bash#devops
typescriptbeginner
Structured JSON Logger
Build a structured logger with log levels, context, child loggers, and JSON output for Node.js services.
Best for: Application logging for production
#nodejs#logging