Add a template for a simple, generic memcached service

This commit is contained in:
Daniel Berteaud 2024-03-22 16:20:09 +01:00
parent a78d1c6676
commit 0f8c3b8c33
1 changed files with 48 additions and 0 deletions

48
templates/task.memcached Normal file
View File

@ -0,0 +1,48 @@
[[- /* vim: syntax=hcl
This is a generic, small and reusable memcached task */ -]]
# Local memcached instance
task "memcached" {
driver = "docker"
user = 11211
lifecycle {
hook = "prestart"
sidecar = true
}
config {
image = "memcached:alpine"
readonly_rootfs = true
force_pull = true
entrypoint = ["/local/memcached"]
}
template {
data =<<_EOT
#!/bin/sh
set -eu
exec memcached -l 127.0.0.1 -p 11211 -m {{ env "NOMAD_MEMORY_LIMIT" | parseInt | subtract 5 }}
_EOT
destination = "local/memcached"
perms = 755
}
resources {
[[- if and (has . "resources") (has .resources "cpu") ]]
cpu = [[ .resources.cpu ]]
[[- else ]]
cpu = 10
[[- end ]]
[[- if and (has . "resources") (has .resources "memory") ]]
memory = [[ .resources.memory ]]
[[- else ]]
memory = 20
[[- end ]]
[[- if and (has . "resources") (has .resources "memory_max") ]]
memory_max = [[ .resources.memory_max ]]
[[- end ]]
}
}