mirror of
https://github.com/juspay/services-flake.git
synced 2024-09-11 12:26:04 +03:00
redis-cluster: run create cluster only if it is not already initalised (#97)
This commit is contained in:
parent
3c3a6f03a2
commit
63ff90eed9
@ -120,12 +120,29 @@ in
|
|||||||
availability.restart = "on_failure";
|
availability.restart = "on_failure";
|
||||||
};
|
};
|
||||||
hosts = lib.mapAttrsToList (_: cfg: "${config.bind}:${builtins.toString cfg.port}") config.nodes;
|
hosts = lib.mapAttrsToList (_: cfg: "${config.bind}:${builtins.toString cfg.port}") config.nodes;
|
||||||
|
clusterCreateScript = pkgs.writeShellApplication {
|
||||||
|
name = "redis-cluster-create";
|
||||||
|
text =
|
||||||
|
let
|
||||||
|
primaryNodePort = (lib.head (lib.mapAttrsToList lib.nameValuePair config.nodes)).value.port;
|
||||||
|
in
|
||||||
|
|
||||||
|
''
|
||||||
|
if ${config.package}/bin/redis-cli --cluster check ${config.bind}:${builtins.toString primaryNodePort}; then
|
||||||
|
echo
|
||||||
|
echo
|
||||||
|
echo "redis-cluster is already created; Skipping initialization"
|
||||||
|
else
|
||||||
|
${config.package}/bin/redis-cli --cluster create ${lib.concatStringsSep " " hosts} --cluster-replicas ${builtins.toString config.replicas} --cluster-yes
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
processes = (lib.mapAttrs' mkNodeProcess config.nodes) // {
|
processes = (lib.mapAttrs' mkNodeProcess config.nodes) // {
|
||||||
"${name}-cluster-create" = {
|
"${name}-cluster-create" = {
|
||||||
depends_on = lib.mapAttrs' (nodeName: cfg: lib.nameValuePair "${name}-${nodeName}" { condition = "process_healthy"; }) config.nodes;
|
depends_on = lib.mapAttrs' (nodeName: cfg: lib.nameValuePair "${name}-${nodeName}" { condition = "process_healthy"; }) config.nodes;
|
||||||
command = "${config.package}/bin/redis-cli --cluster create ${lib.concatStringsSep " " hosts} --cluster-replicas ${builtins.toString config.replicas} --cluster-yes";
|
command = lib.getExe clusterCreateScript;
|
||||||
namespace = name;
|
namespace = name;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user