grep
is a good tool that is common enough to be found in most docker containers that can be used to perform various types of generic health checks.
grep
The following command will check whether port 5613
is open. Note that the following can only guarantee that a numeric port is open from the perspective of the TCP/IP stack, yet it does not perform any "HTTP request" such as the one performed using curl
or wget
. In that sense, this a weaker test that should only be used if some program-specific stronger test cannot be used that would also additionally attest to the proper functionality of the program.
grep -qi ":"`printf '%04x' 5613` /proc/*/net/tcp || exit 1
Due to recent kernels, processes, process numbers and their corresponding command line can be fished out of /proc
, such that the following command, for example:
grep -qa elasticsearch /proc/[0-9]/cmdline || exit 1
will check whether there is a process running whose command line parameters contain the string elasticsearch
.
This is also a very weak test and can only guarantee that whatever string is being searched for is also the name of a process or is contained within the command-line parameters but without being able to say much else.