for other running into this issue as an interim fix I created this docker stack
services:
zammad-watchdog:
image: docker:cli
container_name: zammad-watchdog
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
CONTAINER: zammad-zammad-railsserver-1
LIMIT_MB: "3500"
CHECK_INTERVAL: "300"
COOLDOWN: "1800"
command:
- /bin/sh
- -c
- |
echo "Watching $$CONTAINER; limit=$$LIMIT_MB MB"
LAST_RESTART=0
while true; do
MEM_USAGE=$$(docker stats \
--no-stream \
--format '{{.MemUsage}}' \
"$$CONTAINER" 2>/dev/null | cut -d/ -f1 | xargs)
NOW=$$(date +%s)
case "$$MEM_USAGE" in
*GiB)
VALUE=$$(echo "$$MEM_USAGE" | sed 's/GiB//')
MEM_MB=$$(awk "BEGIN {printf \"%.0f\", $$VALUE * 1024}")
;;
*MiB)
VALUE=$$(echo "$$MEM_USAGE" | sed 's/MiB//')
MEM_MB=$$(awk "BEGIN {printf \"%.0f\", $$VALUE}")
;;
*KiB)
VALUE=$$(echo "$$MEM_USAGE" | sed 's/KiB//')
MEM_MB=$$(awk "BEGIN {printf \"%.0f\", $$VALUE / 1024}")
;;
*)
echo "$$(date): Could not parse memory value: '$$MEM_USAGE'"
MEM_MB=0
;;
esac
echo "$$(date): Railsserver memory=$$MEM_MB MB ($$MEM_USAGE)"
if [ "$$MEM_MB" -ge "$$LIMIT_MB" ] && \
[ $$((NOW - LAST_RESTART)) -ge "$$COOLDOWN" ]; then
echo "$$(date): Memory $$MEM_MB MB >= $$LIMIT_MB MB - restarting $$CONTAINER"
docker restart "$$CONTAINER"
LAST_RESTART=$$NOW
fi
sleep "$$CHECK_INTERVAL"
done
this restarts the zammad-railsserver-1 container when the memory usage reaches 3.5GiB.
I don’t consider this elegant but at least it prevents zammad from dragging down the whole server