create a module for round-robin
This commit is contained in:
27
modules/round-robin/default.nix
Normal file
27
modules/round-robin/default.nix
Normal file
@@ -0,0 +1,27 @@
|
||||
## Round Robin
|
||||
##
|
||||
## Given a list of services, run each in turn until it exits, then
|
||||
## runs the next.
|
||||
|
||||
|
||||
{ lib, pkgs, config, ...}:
|
||||
let
|
||||
inherit (lib) mkOption types;
|
||||
inherit (pkgs) liminix;
|
||||
inherit (pkgs.liminix.services) longrun;
|
||||
in {
|
||||
options = {
|
||||
system.service.round-robin = mkOption {
|
||||
description = "run services one at a time and failover to next";
|
||||
type = liminix.lib.types.serviceDefn;
|
||||
};
|
||||
};
|
||||
config.system.service.round-robin = config.system.callService ./service.nix {
|
||||
services = mkOption {
|
||||
type = types.listOf liminix.lib.types.service;
|
||||
};
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
};
|
||||
};
|
||||
}
|
32
modules/round-robin/service.nix
Normal file
32
modules/round-robin/service.nix
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
liminix, lib, s6-rc-round-robin
|
||||
}:
|
||||
{ services, name} :
|
||||
let
|
||||
inherit (liminix.services) oneshot longrun;
|
||||
controlled-services = builtins.map
|
||||
(s: s.overrideAttrs(o: { inherit controller; }))
|
||||
services;
|
||||
controller = let name' = "control-${name}"; in longrun {
|
||||
name = name';
|
||||
run = ''
|
||||
in_outputs ${name'}
|
||||
exec ${s6-rc-round-robin}/bin/s6-rc-round-robin \
|
||||
-p ${proxy.name} \
|
||||
${lib.concatStringsSep " "
|
||||
(builtins.map (f: f.name) controlled-services)}
|
||||
'';
|
||||
};
|
||||
proxy = oneshot rec {
|
||||
inherit name;
|
||||
inherit controller;
|
||||
buildInputs = controlled-services;
|
||||
up = ''
|
||||
echo start proxy ${name}
|
||||
set -x
|
||||
(in_outputs ${name}
|
||||
cp -rv $(output_path ${controller} active)/* .
|
||||
)
|
||||
'';
|
||||
};
|
||||
in proxy
|
Reference in New Issue
Block a user