|
| 1 | +{ config, pkgs, lib, name, ... }: |
| 2 | + |
| 3 | +{ |
| 4 | + options = { |
| 5 | + package = lib.mkPackageOption pkgs "elasticmq-server-bin" { }; |
| 6 | + |
| 7 | + nodeAddress = { |
| 8 | + protocol = lib.mkOption { |
| 9 | + type = lib.types.str; |
| 10 | + default = "http"; |
| 11 | + }; |
| 12 | + host = lib.mkOption { |
| 13 | + type = lib.types.str; |
| 14 | + default = "localhost"; |
| 15 | + }; |
| 16 | + port = lib.mkOption { |
| 17 | + type = lib.types.port; |
| 18 | + default = 9324; |
| 19 | + }; |
| 20 | + contextPath = lib.mkOption { |
| 21 | + type = lib.types.str; |
| 22 | + default = ""; |
| 23 | + }; |
| 24 | + }; |
| 25 | + |
| 26 | + restSqs = lib.mkOption { |
| 27 | + type = lib.types.submodule { |
| 28 | + options = { |
| 29 | + enabled = lib.mkOption { |
| 30 | + type = lib.types.bool; |
| 31 | + default = true; |
| 32 | + }; |
| 33 | + bindPort = lib.mkOption { |
| 34 | + type = lib.types.port; |
| 35 | + default = 9324; |
| 36 | + }; |
| 37 | + bindHost = lib.mkOption { |
| 38 | + type = lib.types.str; |
| 39 | + default = "0.0.0.0"; |
| 40 | + }; |
| 41 | + }; |
| 42 | + }; |
| 43 | + default = { }; |
| 44 | + }; |
| 45 | + |
| 46 | + restStats = lib.mkOption { |
| 47 | + type = lib.types.submodule { |
| 48 | + options = { |
| 49 | + enabled = lib.mkOption { |
| 50 | + type = lib.types.bool; |
| 51 | + default = true; |
| 52 | + }; |
| 53 | + bindPort = lib.mkOption { |
| 54 | + type = lib.types.port; |
| 55 | + default = 9325; |
| 56 | + }; |
| 57 | + bindHost = lib.mkOption { |
| 58 | + type = lib.types.str; |
| 59 | + default = "0.0.0.0"; |
| 60 | + }; |
| 61 | + }; |
| 62 | + }; |
| 63 | + default = { }; |
| 64 | + }; |
| 65 | + |
| 66 | + generateNodeAddress = lib.mkOption { |
| 67 | + type = lib.types.bool; |
| 68 | + default = false; |
| 69 | + }; |
| 70 | + |
| 71 | + extraOptions = lib.mkOption { |
| 72 | + type = lib.types.lines; |
| 73 | + default = ""; |
| 74 | + description = "Additional raw HOCON options to append."; |
| 75 | + }; |
| 76 | + }; |
| 77 | + |
| 78 | + config.outputs.settings.processes."${name}" = |
| 79 | + let |
| 80 | + confFile = pkgs.writeText "elasticmq.conf" '' |
| 81 | + node-address { |
| 82 | + protocol = ${config.nodeAddress.protocol} |
| 83 | + host = ${config.nodeAddress.host} |
| 84 | + port = ${toString config.nodeAddress.port} |
| 85 | + context-path = "${config.nodeAddress.contextPath}" |
| 86 | + } |
| 87 | +
|
| 88 | + rest-sqs { |
| 89 | + enabled = ${lib.boolToString config.restSqs.enabled} |
| 90 | + bind-port = ${toString config.restSqs.bindPort} |
| 91 | + bind-hostname = "${config.restSqs.bindHost}" |
| 92 | + } |
| 93 | +
|
| 94 | + rest-stats { |
| 95 | + enabled = ${lib.boolToString config.restStats.enabled} |
| 96 | + bind-port = ${toString config.restStats.bindPort} |
| 97 | + bind-hostname = "${config.restStats.bindHost}" |
| 98 | + } |
| 99 | +
|
| 100 | + generate-node-address = ${lib.boolToString config.generateNodeAddress} |
| 101 | +
|
| 102 | + ${config.extraOptions} |
| 103 | + ''; |
| 104 | + |
| 105 | + startCommand = pkgs.writeShellApplication { |
| 106 | + name = "start-elasticmq"; |
| 107 | + runtimeInputs = [ config.package ]; |
| 108 | + runtimeEnv = { |
| 109 | + JAVA_TOOL_OPTIONS = "-Dconfig.file=${confFile}"; |
| 110 | + }; |
| 111 | + text = '' |
| 112 | + exec elasticmq-server |
| 113 | + ''; |
| 114 | + }; |
| 115 | + in |
| 116 | + { |
| 117 | + command = startCommand; |
| 118 | + |
| 119 | + readiness_probe = lib.optionalAttrs config.restSqs.enabled { |
| 120 | + http_get = { |
| 121 | + host = config.restSqs.bindHost; |
| 122 | + port = config.restSqs.bindPort; |
| 123 | + path = "/health"; |
| 124 | + }; |
| 125 | + initial_delay_seconds = 2; |
| 126 | + period_seconds = 10; |
| 127 | + timeout_seconds = 4; |
| 128 | + success_threshold = 1; |
| 129 | + failure_threshold = 5; |
| 130 | + }; |
| 131 | + # https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy |
| 132 | + availability = { |
| 133 | + restart = "on_failure"; |
| 134 | + max_restarts = 5; |
| 135 | + }; |
| 136 | + }; |
| 137 | +} |
0 commit comments