12 meta.maintainers = [ lib.maintainers.tie ];
14 nodes = lib.listToAttrs (lib.imap0
17 value = { config, ... }: {
18 services.centrifugo = {
22 port = centrifugoPort;
23 # See https://centrifugal.dev/docs/server/engines#redis-sharding
25 # Connect to local Redis shard via Unix socket.
27 let toRedisAddresses = map (name: "${name}:${toString redisPort}"); in
28 toRedisAddresses (lib.take index nodes) ++ [
29 "unix://${config.services.redis.servers.centrifugo.unixSocket}"
30 ] ++ toRedisAddresses (lib.drop (index + 1) nodes);
31 usage_stats_disable = true;
35 config.services.redis.servers.centrifugo.user
38 services.redis.servers.centrifugo = {
40 bind = null; # all interfaces
43 settings.protected-mode = false;
52 redisPort = ${toString redisPort}
53 centrifugoPort = ${toString centrifugoPort}
57 for machine in machines:
58 machine.wait_for_unit("redis-centrifugo.service")
59 machine.wait_for_open_port(redisPort)
61 for machine in machines:
62 machine.wait_for_unit("centrifugo.service")
63 machine.wait_for_open_port(centrifugoPort)
65 # See https://centrifugal.dev/docs/server/server_api#info
66 def list_nodes(machine):
67 curl = "curl --fail-with-body --silent"
69 resp = json.loads(machine.succeed(f"{curl} -d '{body}' http://localhost:{centrifugoPort}/api/info"))
70 return resp["result"]["nodes"]
71 machineNames = {m.name for m in machines}
72 for machine in machines:
73 nodes = list_nodes(machine)
74 assert len(nodes) == len(machines)
75 nodeNames = {n['name'] for n in nodes}
76 assert machineNames == nodeNames