From 27a77fc3b80accccb0e1285b51fd117794f6a3f5 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Wed, 1 Feb 2017 21:37:48 +0300 Subject: php-fpm: enable logrotate --- modules/apps/php-fpm.nix | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'modules/apps/php-fpm.nix') diff --git a/modules/apps/php-fpm.nix b/modules/apps/php-fpm.nix index ed90c1a..cdc83c6 100644 --- a/modules/apps/php-fpm.nix +++ b/modules/apps/php-fpm.nix @@ -4,12 +4,14 @@ let inherit (builtins) filter isAttrs isBool ; + inherit (lib) - concatStringsSep filterAttrs foldl hasPrefix - mapAttrsToList mkIf mkOption types ; - inherit (types) - attrsOf bool either enum int nullOr package path str - submodule ; + concatStringsSep filterAttrs foldl hasPrefix mapAttrs' mapAttrsToList + mkDefault mkIf mkOption ; + + inherit (lib.types) + attrsOf bool either enum int nullOr package path str submodule ; + explicit = filterAttrs (n: v: n != "_module" && v != null); concatNonEmpty = sep: list: concatStringsSep sep (filter (s: s != "") list); @@ -23,6 +25,26 @@ let users = mapAttrsToList (_: v: v.user) instances; + mkLogRotate = name: cfg: + let instance = "php-fpm-${name}"; + in { + name = instance; + value = { + files = "${cfg.logDir}/*.log"; + directives = { + delaycompress = mkDefault true; + missingok = mkDefault true; + notifempty = mkDefault true; + rotate = mkDefault 14; + sharedscripts = true; + daily = mkDefault true; + create = mkDefault "0640 ${cfg.user} ${cfg.user}"; + postrotate = pkgs.writeBashScript "logrotate-${instance}-postrotate" + "systemctl kill -s SIGUSR1 --kill-who=main '${instance}.service'"; + }; + }; + }; + mkService = name: cfg: let show = v: if isBool v then (if v then "yes" else "no") else toString v; @@ -72,6 +94,7 @@ let ''; serviceConfig = { ExecStart = exec; + KillMode = "mixed"; PermissionsStartOnly = true; Restart = "always"; User = cfg.user; @@ -162,6 +185,7 @@ in { }))); config = mkIf ({} != instances) { + nixsap.apps.logrotate.conf = mapAttrs' mkLogRotate instances; nixsap.system.users.daemons = users; systemd.services = foldl (a: b: a//b) {} (mapAttrsToList mkService instances); }; -- cgit v1.2.3