You need to rotate a custom application's log every hour, not daily. How?
AdvancedScenarioScheduling, automation and scripting
Answer
Situation read → logrotate runs daily by default; it needs an hourly trigger.
What I'd do →
- Config
/etc/logrotate.hourly.d/app:
/var/log/app/app.log {
hourly
rotate 48
compress
missingok
postrotate
systemctl kill -s HUP app.service
endscript
}
- A timer or
/etc/cron.hourly/logrotate-hourlyrunninglogrotate /etc/logrotate.hourly.d/app. - Test with
logrotate -d(debug) and-f(force).
Why → The hourly directive only works if logrotate itself is invoked every hour.
Interview tip → Mention that postrotate signalling is safer than copytruncate, which can lose lines.
More on Scheduling, automation and scripting
A database dump must run every night at 1:30 AM. How do you schedule it with cron so it is reliable?BeginnerConvert that nightly cron job to a systemd timer. Why would you?IntermediateA cron job runs every 5 minutes, but sometimes takes 8 minutes and two copies overlap, corrupting data. How do you prevent that?BeginnerYou have 300 servers running the same cron job at midnight, and they hammer a shared API. How do you fix it?IntermediateA job must run on the last day of every month. Cron has no "last day" field. What do you do?IntermediateYou inherited a server and need to know every scheduled job on it. Where do you look?Beginner