aboutsummaryrefslogtreecommitdiff
path: root/modules/apps
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-02-01 21:37:48 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-02-01 21:58:45 +0300
commit27a77fc3b80accccb0e1285b51fd117794f6a3f5 (patch)
treeb021461363c8a036a7458a9414315339a4b918ea /modules/apps
parent809a35ba85df0a202d26d9ee8cfa474c7eecdf99 (diff)
downloadnixsap-27a77fc3b80accccb0e1285b51fd117794f6a3f5.tar.gz
php-fpm: enable logrotate
Diffstat (limited to 'modules/apps')
-rw-r--r--modules/apps/php-fpm.nix34
1 files changed, 29 insertions, 5 deletions
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);
};