Interview Prep/Linux/Scheduling, automation and scripting

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 →

  1. Config /etc/logrotate.hourly.d/app:
/var/log/app/app.log {
    hourly
    rotate 48
    compress
    missingok
    postrotate
        systemctl kill -s HUP app.service
    endscript
}
  1. A timer or /etc/cron.hourly/logrotate-hourly running logrotate /etc/logrotate.hourly.d/app.
  2. 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.

All Linux questions Roadmap: Linux

More on Scheduling, automation and scripting