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.
28 otherNodes = lib.take index nodes ++ lib.drop (index + 1) nodes;
30 map (name: "${name}:${toString redisPort}") otherNodes ++ [
31 "unix://${config.services.redis.servers.centrifugo.unixSocket}"
33 usage_stats_disable = true;
37 config.services.redis.servers.centrifugo.user
40 services.redis.servers.centrifugo = {
42 bind = null; # all interfaces
45 settings.protected-mode = false;
54 redisPort = ${toString redisPort}
55 centrifugoPort = ${toString centrifugoPort}
59 for machine in machines:
60 machine.wait_for_unit("redis-centrifugo.service")
61 machine.wait_for_open_port(redisPort)
63 for machine in machines:
64 machine.wait_for_unit("centrifugo.service")
65 machine.wait_for_open_port(centrifugoPort)
67 # See https://centrifugal.dev/docs/server/server_api#info
68 def list_nodes(machine):
69 curl = "curl --fail-with-body --silent"
71 resp = json.loads(machine.succeed(f"{curl} -d '{body}' http://localhost:{centrifugoPort}/api/info"))
72 return resp["result"]["nodes"]
73 machineNames = {m.name for m in machines}
74 for machine in machines:
75 nodes = list_nodes(machine)
76 assert len(nodes) == len(machines)
77 nodeNames = {n['name'] for n in nodes}
78 assert machineNames == nodeNames