default.nix (1388B)
1 ## Health check 2 ## 3 ## Runs a service and a separate periodic health process. When the 4 ## health check starts failing over a period of time, kill the service. 5 ## (Usually that means the supervisor will restart it, but you can 6 ## have other behaviours by e.g. combining this service with a round-robin 7 ## for failover) 8 9 { 10 lib, 11 pkgs, 12 config, 13 ... 14 }: 15 let 16 inherit (lib) mkOption types; 17 inherit (pkgs) liminix; 18 in 19 # inherit (pkgs.liminix.services) longrun; 20 { 21 options = { 22 system.service.health-check = mkOption { 23 description = "run a service while periodically checking it is healthy"; 24 type = liminix.lib.types.serviceDefn; 25 }; 26 }; 27 config.system.service.health-check = config.system.callService ./service.nix { 28 service = mkOption { 29 type = liminix.lib.types.service; 30 }; 31 interval = mkOption { 32 description = "interval between checks, in seconds"; 33 type = types.int; 34 default = 10; 35 example = 10; 36 }; 37 threshold = mkOption { 38 description = "number of consecutive failures required for the service to be kicked"; 39 type = types.int; 40 example = 3; 41 }; 42 healthCheck = mkOption { 43 description = "health check command or script. Expected to exit 0 if the service is healthy or any other exit status otherwise"; 44 type = types.path; 45 }; 46 }; 47 config.programs.busybox.applets = [ "expr" ]; 48 }