memcached icon indicating copy to clipboard operation
memcached copied to clipboard

Healthcheck script

Open kaznovac opened this issue 2 years ago • 7 comments

As a developer I'd like to have a way to issue a health check on memcached container without modifying the base image (base image has no telnet nor nc)

kaznovac avatar Sep 21 '23 10:09 kaznovac

The following works on alpine:

echo "version" | nc -vn -w 1 127.0.0.1 11211

Source: https://book.hacktricks.xyz/network-services-pentesting/11211-memcache

LaurentGoderre avatar Sep 25 '23 13:09 LaurentGoderre

And the following works on debian:

echo "version" | (exec 3<>/dev/tcp/localhost/11211; cat >&3; cat <&3; exec 3<&-)

LaurentGoderre avatar Sep 25 '23 14:09 LaurentGoderre

@LaurentGoderre Wow, thanks a lot, just what I've needed! (couldn't figure out the 'bidirectional' cat on my own)

I've added timeout to your debian command, so it will not block (just need to figure out the clean way to get the exit code)

echo "version" | (exec 3<>/dev/tcp/localhost/11211; cat >&3; timeout 0.1 cat <&3; exec 3<&-)

If it's ok with you I'd like to create PR to update the documentation of the image (later when I get some free time)

kaznovac avatar Sep 26 '23 08:09 kaznovac

Absolutely! That would be awesome!

LaurentGoderre avatar Sep 26 '23 13:09 LaurentGoderre

See https://github.com/docker-library/faq#healthcheck :see_no_evil:

tianon avatar Dec 08 '23 23:12 tianon

@tianon an example could be created here then: https://github.com/docker-library/healthcheck

LaurentGoderre avatar Dec 11 '23 14:12 LaurentGoderre

Agreed! Does memcached have an explicit healthcheck type function we could use, or is just connecting the best we can do? For example, in SQL-based images, I've often used SELECT 1 as a basic health check because I can verify that the output of that query is exactly 1 to know that everything actually worked end-to-end (and it wasn't just something else accepting my connection and quietly doing nothing useful).

tianon avatar Dec 13 '23 23:12 tianon