-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DPE-5600] Add pgBackRest logrotate configuration (#722)
* Add pgBackRest logrotate configuration Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Update how logrotate starts Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Fix unit tests Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> * Add unit tests Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com> --------- Signed-off-by: Marcelo Henrique Neppel <marcelo.neppel@canonical.com>
- Loading branch information
1 parent
2a53fa3
commit 9a7e4e6
Showing
8 changed files
with
134 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
"""Service for rotating logs.""" | ||
|
||
import subprocess | ||
import time | ||
|
||
|
||
def main(): | ||
"""Main loop that calls logrotate.""" | ||
while True: | ||
subprocess.run(["logrotate", "-f", "/etc/logrotate.d/pgbackrest.logrotate"]) | ||
|
||
# Wait 60 seconds before executing logrotate again. | ||
time.sleep(60) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/var/log/pgbackrest/*.log { | ||
rotate 10 | ||
missingok | ||
notifempty | ||
nocompress | ||
daily | ||
create 0600 postgres postgres | ||
dateext | ||
dateformat -%Y%m%d_%H:%M.log | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
from unittest.mock import call, patch | ||
|
||
from rotate_logs import main | ||
|
||
|
||
def test_main(): | ||
with patch("subprocess.run") as _run, patch( | ||
"time.sleep", side_effect=[None, InterruptedError] | ||
) as _sleep: | ||
try: | ||
main() | ||
except InterruptedError: | ||
pass | ||
assert _run.call_count == 2 | ||
run_call = call(["logrotate", "-f", "/etc/logrotate.d/pgbackrest.logrotate"]) | ||
_run.assert_has_calls([run_call, run_call]) | ||
assert _sleep.call_count == 2 | ||
sleep_call = call(60) | ||
_sleep.assert_has_calls([sleep_call, sleep_call]) |