redis
This commit is contained in:
@@ -227,10 +227,36 @@ in
|
|||||||
OOMScoreAdjust = "-900";
|
OOMScoreAdjust = "-900";
|
||||||
};
|
};
|
||||||
|
|
||||||
in listToAttrs (map (serviceName: {
|
# Redis service optimizations
|
||||||
name = serviceName;
|
redisServiceConfigs = listToAttrs (map (serviceName: {
|
||||||
value = { inherit serviceConfig; };
|
name = serviceName;
|
||||||
}) redisServices);
|
value = { inherit serviceConfig; };
|
||||||
|
}) redisServices);
|
||||||
|
|
||||||
|
# Cluster initialization service
|
||||||
|
clusterInitService = mkIf cfg.createCluster {
|
||||||
|
redis-cluster-init = {
|
||||||
|
description = "Initialize Redis Cluster";
|
||||||
|
after = map (i: "redis-master-${toString i}.service") (range 0 (cfg.masters - 1));
|
||||||
|
wants = map (i: "redis-master-${toString i}.service") (range 0 (cfg.masters - 1));
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
RemainAfterExit = true;
|
||||||
|
ExecStart = let
|
||||||
|
masterNodes = concatStringsSep " " (map (i:
|
||||||
|
"${cfg.announceIp}:${toString (cfg.basePort + i)}"
|
||||||
|
) (range 0 (cfg.masters - 1)));
|
||||||
|
in "${pkgs.redis}/bin/redis-cli --cluster create ${masterNodes} --cluster-replicas ${toString cfg.replicasPerMaster} --cluster-yes";
|
||||||
|
|
||||||
|
# Wait for Redis instances to be ready
|
||||||
|
ExecStartPre = "${pkgs.bash}/bin/bash -c 'for i in {1..30}; do ${pkgs.redis}/bin/redis-cli -p ${toString cfg.basePort} ping && break || sleep 2; done'";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
in redisServiceConfigs // clusterInitService;
|
||||||
|
|
||||||
# Firewall configuration
|
# Firewall configuration
|
||||||
networking.firewall = mkIf cfg.openFirewall {
|
networking.firewall = mkIf cfg.openFirewall {
|
||||||
@@ -244,27 +270,6 @@ in
|
|||||||
(map (i: cfg.basePort + cfg.masters + i + 10000) (range 0 (cfg.masters * cfg.replicasPerMaster - 1)));
|
(map (i: cfg.basePort + cfg.masters + i + 10000) (range 0 (cfg.masters * cfg.replicasPerMaster - 1)));
|
||||||
};
|
};
|
||||||
|
|
||||||
# Cluster initialization script
|
|
||||||
systemd.services.redis-cluster-init = mkIf cfg.createCluster {
|
|
||||||
description = "Initialize Redis Cluster";
|
|
||||||
after = map (i: "redis-master-${toString i}.service") (range 0 (cfg.masters - 1));
|
|
||||||
wants = map (i: "redis-master-${toString i}.service") (range 0 (cfg.masters - 1));
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "oneshot";
|
|
||||||
RemainAfterExit = true;
|
|
||||||
ExecStart = let
|
|
||||||
masterNodes = concatStringsSep " " (map (i:
|
|
||||||
"${cfg.announceIp}:${toString (cfg.basePort + i)}"
|
|
||||||
) (range 0 (cfg.masters - 1)));
|
|
||||||
in "${pkgs.redis}/bin/redis-cli --cluster create ${masterNodes} --cluster-replicas ${toString cfg.replicasPerMaster} --cluster-yes";
|
|
||||||
|
|
||||||
# Wait for Redis instances to be ready
|
|
||||||
ExecStartPre = "${pkgs.bash}/bin/bash -c 'for i in {1..30}; do ${pkgs.redis}/bin/redis-cli -p ${toString cfg.basePort} ping && break || sleep 2; done'";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# Cluster management utilities
|
# Cluster management utilities
|
||||||
environment.systemPackages = [ pkgs.redis ];
|
environment.systemPackages = [ pkgs.redis ];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user