Skip to content

Commit 67f0395

Browse files
authored
Best effort start/stop logrotate.timer systemd service for loganalyzer (#5582)
What is the motivation for this PR? PR #5414 introduced code to stop/start the logrotate.timer systemd service for loganalyzer. On older images that do not have the logrotate.timer service, this operation will fail. How did you do it? This change made stopping/starting logrotate.time a best effort operation. Signed-off-by: Xin Wang <[email protected]>
1 parent fa0507a commit 67f0395

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tests/common/plugins/loganalyzer/loganalyzer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ def __enter__(self):
3232
"""
3333
Disable logrotate cron task / systemd timer and make sure the running logrotate is stopped.
3434
"""
35-
# Disable logrotate systemd timer
36-
self.ansible_host.command("systemctl stop logrotate.timer")
35+
# Disable logrotate systemd timer by best effort. The reason is that logrotate.timer service is not
36+
# available in older version like 201911.
37+
self.ansible_host.command("systemctl stop logrotate.timer", module_ignore_errors=True)
3738
# Disable logrotate cron task
3839
self.ansible_host.command("sed -i 's/^/#/g' /etc/cron.d/logrotate")
3940
logging.debug("Waiting for logrotate from previous cron task or systemd timer run to finish")
@@ -57,8 +58,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
5758
"""
5859
# Enable logrotate cron task back
5960
self.ansible_host.command("sed -i 's/^#//g' /etc/cron.d/logrotate")
60-
# Enable logrotate systemd timer
61-
self.ansible_host.command("systemctl start logrotate.timer")
61+
# Enable logrotate systemd timer by best effort. The reason is that logrotate.timer service is not
62+
# available in older version like 201911.
63+
self.ansible_host.command("systemctl start logrotate.timer", module_ignore_errors=True)
6264

6365

6466
class LogAnalyzerError(Exception):

0 commit comments

Comments
 (0)