~sumner/nixos-configuration

329189ee50c2bdc3098940211bd6010bd4b858be — Sumner Evans a month ago 77d5f4f
logrotate: more agressively prune matrix logs
1 files changed, 24 insertions(+), 19 deletions(-)

M modules/services/logrotate.nix
M modules/services/logrotate.nix => modules/services/logrotate.nix +24 -19
@@ 1,25 1,30 @@
{ config, lib, ... }: with lib;
{ config, lib, ... }: with lib; let
  mkNginxLogsRotate = pathGlob: keep: {
    inherit keep;
    user = "nginx";
    group = "nginx";
    path = "/var/log/nginx/${pathGlob}.log";
    extraConfig = ''
      size 25M
      missingok
      compress
      delaycompress
      notifempty
      create 0644 nginx nginx
      sharedscripts
      postrotate
        /usr/bin/env kill -USR1 `cat /run/nginx/nginx.pid 2>/dev/null` 2>/dev/null || true
      endscript
    '';
  };
in
mkIf config.services.logrotate.enable {
  services.logrotate = {
    paths = {
      "nginx" = mkIf config.services.nginx.enable {
        user = "nginx";
        keep = 10;
        group = "nginx";
        path = "/var/log/nginx/*.log";
        extraConfig = ''
          size 25M
          missingok
          compress
          delaycompress
          notifempty
          create 0644 nginx nginx
          sharedscripts
          postrotate
            /usr/bin/env kill -USR1 `cat /run/nginx/nginx.pid 2>/dev/null` 2>/dev/null || true
          endscript
        '';
      };
      "nginx-sumnerevans-site" = mkIf config.services.nginx.enable (mkNginxLogsRotate "*sumnerevans.com*" 5);
      "nginx-tef" = mkIf config.services.nginx.enable (mkNginxLogsRotate "*the-evans.family*" 2);
      "nginx-matrix" = mkIf config.services.nginx.enable (mkNginxLogsRotate "matrix*" 2);
      "nginx-access-log" = mkIf config.services.nginx.enable (mkNginxLogsRotate "access*" 2);
    };
  };
}