Linux Labs

Packages, services, and logs / Stage 12 of 13

Log rotation and retention

Not running Starting usually ~20 s
Leave the lesson

Step 7 of 9 · lab · 20 minmedium

Set up log rotation

A service writes to a log that grows without limit. Set up logrotate for it so that the service keeps writing after rotation.

Situation

The myapp service appends a line to /var/log/myapp/app.log every two seconds. The log has no rotation: the file is already large and keeps growing. It needs proper rotation with logrotate.

Task

  1. A rule sits in its own file, /etc/logrotate.d/myapp, covers /var/log/myapp/app.log and parses in logrotate without errors.
  2. Under this rule the log rotates daily, seven old files are kept, and old files are compressed.
  3. One rotation has already run: the log's old contents sit in an archive next to it.
  4. After the rotation the myapp service keeps writing to /var/log/myapp/app.log.
  5. Later rotations by this rule do not take the service's writes away from app.log either.

Constraints

  • Do not change the myapp service or its program, /usr/local/bin/myapp.
  • Do not delete the log's old contents.

The tools you need are already installed. There's no internet on this machine.

Lab · on your own

No commands are given in this lab: type them in the terminal yourself. Goals are checked on the machine after every command.

Goals

0 of 5
  • The /etc/logrotate.d/myapp rule covers /var/log/myapp/app.log and parses without errors — not done yet
  • Under the rule the log rotates daily, seven old files are kept and old files are compressed — not done yet
  • Rotation has run — the log's old contents sit in an archive — not done yet
  • After rotation the myapp service writes to /var/log/myapp/app.log — not done yet
  • Later rotations by the rule do not take the service's writes away from app.log either — not done yet
Ctrl+Enter
Starts the machine node1 · Ubuntu 24.04

The machine is starting

Hints

0 of 3

Lab goals

0 of 5
  • The /etc/logrotate.d/myapp rule covers /var/log/myapp/app.log and parses without errors — not done yet
  • Under the rule the log rotates daily, seven old files are kept and old files are compressed — not done yet
  • Rotation has run — the log's old contents sit in an archive — not done yet
  • After rotation the myapp service writes to /var/log/myapp/app.log — not done yet
  • Later rotations by the rule do not take the service's writes away from app.log either — not done yet
node1 Ubuntu 24.04

Lab goals

0 of 5
  • The /etc/logrotate.d/myapp rule covers /var/log/myapp/app.log and parses without errors — not done yet
  • Under the rule the log rotates daily, seven old files are kept and old files are compressed — not done yet
  • Rotation has run — the log's old contents sit in an archive — not done yet
  • After rotation the myapp service writes to /var/log/myapp/app.log — not done yet
  • Later rotations by the rule do not take the service's writes away from app.log either — not done yet
Loading…