Skip to content

Commit 92cbfe9

Browse files
committed
(WIP) Install logrotate using system manager
1 parent 8fac60d commit 92cbfe9

File tree

5 files changed

+90
-1
lines changed

5 files changed

+90
-1
lines changed

nix/packages/docker-ubuntu.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@ let
1414
in
1515
runCommand "ubuntu-cloudimg" { nativeBuildInputs = [ xz ]; } ''
1616
mkdir -p $out
17+
# Remove (among other things) builtin logrotate to avoid conflicts with the one set-up by system-manager
1718
tar --exclude='dev/*' \
1819
--exclude='etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service' \
1920
--exclude='etc/systemd/system/multi-user.target.wants/systemd-resolved.service' \
21+
--exclude='etc/systemd/system/timers.target.wants/logrotate.timer' \
2022
--exclude='usr/lib/systemd/system/tpm-udev.service' \
2123
--exclude='usr/lib/systemd/system/systemd-remount-fs.service' \
2224
--exclude='usr/lib/systemd/system/systemd-resolved.service' \
25+
--exclude='usr/lib/systemd/system/logrotate.service' \
26+
--exclude='usr/lib/systemd/system/logrotate.timer' \
2327
--exclude='usr/lib/systemd/system/proc-sys-fs-binfmt_misc.automount' \
2428
--exclude='usr/lib/systemd/system/sys-kernel-*' \
2529
--exclude='var/lib/apt/lists/*' \

nix/systemConfigs.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{ self, inputs, ... }:
22
let
33
mkModules = system: [
4+
self.systemModules.logrotate
45
({
56
services.nginx.enable = true;
67
nixpkgs.hostPlatform = system;
8+
supabase.services.logrotate.enable = true;
79
})
810
];
911

nix/systemModules/default.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
{
55
imports = [ ./tests ];
66
flake = {
7-
systemModules = { };
7+
systemModules = {
8+
logrotate = ./logrotate.nix;
9+
};
810
};
911
}

nix/systemModules/logrotate.nix

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
lib,
3+
nixosModulesPath,
4+
config,
5+
...
6+
}:
7+
let
8+
cfg = config.supabase.services.logrotate;
9+
in
10+
{
11+
imports = map (path: nixosModulesPath + path) [
12+
# FIXME: error: The option `services.logrotate' in module `/nix/store/...-source/nix/modules'
13+
# would be a parent of the following options,but its type `attribute set' does not support nested options.
14+
# "/services/logging/logrotate.nix"
15+
];
16+
17+
options = {
18+
supabase.services.logrotate = {
19+
enable = lib.mkEnableOption "Whether to enable the logrotate systemd service.";
20+
};
21+
};
22+
23+
config = lib.mkIf cfg.enable {
24+
services.logrotate = {
25+
enable = true;
26+
settings = {
27+
"/var/log/postgresql/auth-failures.csv" = {
28+
size = "10M";
29+
rotate = 5;
30+
compress = true;
31+
delaycompress = true;
32+
notifempty = true;
33+
missingok = true;
34+
};
35+
"/var/log/postgresql/postgresql.csv" = {
36+
size = "50M";
37+
rotate = 9;
38+
compress = true;
39+
delaycompress = true;
40+
notifempty = true;
41+
missingok = true;
42+
postrotate = ''
43+
sudo -u postgres /usr/lib/postgresql/bin/pg_ctl -D /var/lib/postgresql/data logrotate
44+
'';
45+
};
46+
"/var/log/postgresql/postgresql.log" = {
47+
size = "50M";
48+
rotate = 3;
49+
copytruncate = true;
50+
delaycompress = true;
51+
compress = true;
52+
notifempty = true;
53+
missingok = true;
54+
};
55+
"/var/log/wal-g/*.log" = {
56+
size = "50M";
57+
rotate = 3;
58+
copytruncate = true;
59+
delaycompress = true;
60+
compress = true;
61+
notifempty = true;
62+
missingok = true;
63+
};
64+
};
65+
};
66+
67+
# FIXME: logrotate.service isn't a valid unit file (missing ExecStart)
68+
# systemd.services.logrotate = {
69+
# wantedBy = lib.mkForce [
70+
# "system-manager.target"
71+
# ];
72+
# };
73+
};
74+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# from time import sleep
2+
3+
4+
def test_logrotate_service(host):
5+
# sleep(5000) # Handy for interactive debugging (with docker exec -it $CONTAINER_ID /bin/bash)
6+
assert host.service("logrotate.service").is_valid
7+
assert host.service("logrotate.service").is_running, "Logrotate service should be running but failed: {}".format(host.run("systemctl status logrotate.service").stdout)

0 commit comments

Comments
 (0)