Step 7 of 9 · lab · 20 min
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
- A rule sits in its own file,
/etc/logrotate.d/myapp, covers/var/log/myapp/app.logand parses in logrotate without errors. - Under this rule the log rotates daily, seven old files are kept, and old files are compressed.
- One rotation has already run: the log's old contents sit in an archive next to it.
- After the rotation the
myappservice keeps writing to/var/log/myapp/app.log. - Later rotations by this rule do not take the service's writes away from
app.logeither.
Constraints
- Do not change the
myappservice 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 3Lab 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
Goals are checked on the machine after every command.