diff --git a/doc/memcached.md b/doc/memcached.md new file mode 100644 index 00000000..27c3652e --- /dev/null +++ b/doc/memcached.md @@ -0,0 +1,9 @@ +# Memcached + +[memcached](https://www.memcached.org/) is a high-performance, distributed memory object caching system, generic in nature, but originally intended for use in speeding up dynamic web applications by alleviating database load. + +You can think of it as a short-term memory for your applications. + +## Usage example + + diff --git a/doc/services.md b/doc/services.md index 81aeff32..c52ac0dc 100644 --- a/doc/services.md +++ b/doc/services.md @@ -5,21 +5,22 @@ short-title: Services # Supported services - [[apache-kafka]]# +- [[cassandra]]# - [[clickhouse]]# - [[elasticsearch]]# +- [[grafana]]# + - [[tempo]] +- [[memcached]]# - [[mysql]]# - [[nginx]]# - [[ollama]]# - [[open-webui]]# - [[postgresql]]# - [[pgadmin]] +- [[prometheus]]# - [[redis]]# - [[redis-cluster]] - [[searxng]]# - [[tika]]# -- [[zookeeper]]# -- [[grafana]]# - - [[tempo]] -- [[prometheus]]# -- [[cassandra]]# - [[weaviate]]# +- [[zookeeper]]# diff --git a/nix/services/default.nix b/nix/services/default.nix index e02e2b04..5591c5e3 100644 --- a/nix/services/default.nix +++ b/nix/services/default.nix @@ -15,6 +15,7 @@ in ./redis.nix ./zookeeper.nix ./grafana.nix + ./memcached.nix ./prometheus.nix ./pgadmin.nix ./cassandra.nix diff --git a/nix/services/memcached.nix b/nix/services/memcached.nix new file mode 100644 index 00000000..be6b7103 --- /dev/null +++ b/nix/services/memcached.nix @@ -0,0 +1,62 @@ +# Based on https://github.com/cachix/devenv/blob/main/src/modules/services/memcached.nix +{ pkgs, lib, name, config, ... }: +let + inherit (lib) types; +in +{ + options = { + package = lib.mkPackageOption pkgs "memcached" { }; + + bind = lib.mkOption { + type = types.nullOr types.str; + default = "127.0.0.1"; + description = '' + The IP interface to bind to. + `null` means "all interfaces". + ''; + example = "127.0.0.1"; + }; + + port = lib.mkOption { + type = types.port; + default = 11211; + description = '' + The TCP port to accept connections. + + If port 0 is specified memcached will not listen on a TCP socket. + ''; + }; + + startArgs = lib.mkOption { + type = types.listOf types.lines; + default = [ ]; + example = [ "--memory-limit=100M" ]; + description = '' + Additional arguments passed to `memcached` during startup. + ''; + }; + }; + + config = { + outputs.settings.processes.${name} = { + command = "${config.package}/bin/memcached --port=${toString config.port} --listen=${config.bind} ${lib.concatStringsSep " " config.startArgs}"; + + readiness_probe = { + exec.command = '' + echo -e "stats\nquit" | ${pkgs.netcat}/bin/nc ${config.bind} ${toString config.port} > /dev/null 2>&1 + ''; + initial_delay_seconds = 2; + period_seconds = 10; + timeout_seconds = 4; + success_threshold = 1; + failure_threshold = 5; + }; + + # https://github.com/F1bonacc1/process-compose#-auto-restart-if-not-healthy + availability = { + restart = "on_failure"; + max_restarts = 5; + }; + }; + }; +} diff --git a/nix/services/memcached_test.nix b/nix/services/memcached_test.nix new file mode 100644 index 00000000..a24ff990 --- /dev/null +++ b/nix/services/memcached_test.nix @@ -0,0 +1,23 @@ +{ pkgs, config, ... }: +{ + services.memcached."memcached1".enable = true; + + settings.processes.test = + let + cfg = config.services.memcached."memcached1"; + in + { + command = pkgs.writeShellApplication { + runtimeInputs = [ + cfg.package + pkgs.gnugrep + pkgs.netcat + ]; + text = '' + echo -e "stats\nquit" | nc 127.0.0.1 11211 | grep "STAT version" + ''; + name = "memcached-test"; + }; + depends_on."memcached1".condition = "process_healthy"; + }; +} diff --git a/test/flake.nix b/test/flake.nix index 2e6fc634..4f664c25 100644 --- a/test/flake.nix +++ b/test/flake.nix @@ -50,6 +50,7 @@ "${inputs.services-flake}/nix/services/tempo_test.nix" "${inputs.services-flake}/nix/services/weaviate_test.nix" "${inputs.services-flake}/nix/services/tika_test.nix" + "${inputs.services-flake}/nix/services/memcached_test.nix" ])); }; };