2022-02-11 09:49:52 +01:00
|
|
|
# Test logrotate service works and is enabled by default
|
|
|
|
|
|
|
|
import ./make-test-python.nix ({ pkgs, ...} : rec {
|
|
|
|
name = "logrotate";
|
|
|
|
meta = with pkgs.lib.maintainers; {
|
|
|
|
maintainers = [ martinetd ];
|
|
|
|
};
|
|
|
|
|
|
|
|
# default machine
|
|
|
|
machine = { ... }: {
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript =
|
|
|
|
''
|
|
|
|
with subtest("whether logrotate works"):
|
|
|
|
machine.succeed(
|
|
|
|
# we must rotate once first to create logrotate stamp
|
2022-02-26 08:04:44 +01:00
|
|
|
"systemctl start logrotate.service")
|
|
|
|
# we need to wait for console text once here to
|
|
|
|
# clear console buffer up to this point for next wait
|
|
|
|
machine.wait_for_console_text('logrotate.service: Deactivated successfully')
|
2022-02-11 09:49:52 +01:00
|
|
|
|
2022-02-26 08:04:44 +01:00
|
|
|
machine.succeed(
|
2022-02-11 09:49:52 +01:00
|
|
|
# wtmp is present in default config.
|
|
|
|
"rm -f /var/log/wtmp*",
|
2022-02-26 23:04:18 +01:00
|
|
|
# we need to give it at least 1MB
|
|
|
|
"dd if=/dev/zero of=/var/log/wtmp bs=2M count=1",
|
2022-02-11 09:49:52 +01:00
|
|
|
|
2022-02-26 08:04:44 +01:00
|
|
|
# move into the future and check rotation.
|
|
|
|
"date -s 'now + 1 month + 1 day'")
|
|
|
|
machine.wait_for_console_text('logrotate.service: Deactivated successfully')
|
|
|
|
machine.succeed(
|
2022-02-11 09:49:52 +01:00
|
|
|
# check rotate worked
|
|
|
|
"[ -e /var/log/wtmp.1 ]",
|
|
|
|
)
|
|
|
|
'';
|
|
|
|
})
|