-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added memcached service (#314)
- Loading branch information
1 parent
e0a19db
commit c196208
Showing
6 changed files
with
102 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
<https://github.com/juspay/services-flake/blob/main/nix/services/memcached_test.nix> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters