| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Curl uses a lot of different return codes. The healthcheck however expects just 0 or 1. || exit 1 converts return codes > 1 to 1. I don't like the new approach, because it pollutes the mail.log every 30 seconds with something like: Jun 1 12:45:32 mail postfix/postscreen[18492]: CONNECT from [127.0.0.1]:46020 to [127.0.0.1]:25 Jun 1 12:45:32 mail postfix/postscreen[18492]: ALLOWLISTED [127.0.0.1]:46020 Jun 1 12:45:32 mail postfix/smtpd[18493]: connect from localhost[127.0.0.1] Jun 1 12:45:32 mail opendmarc[2397]: ignoring connection from localhost Jun 1 12:45:32 mail postfix/smtpd[18493]: lost connection after CONNECT from localhost[127.0.0.1] Jun 1 12:45:32 mail postfix/smtpd[18493]: disconnect from localhost[127.0.0.1] commands=0/0 This might also introduce problems with fail2ban. IIRC using mode ddos or agressive, it looks for "connect" / "disconnect" patterns. Edit: To achieve a cleaner output, we could use: ss --ipv4 --listening --tcp --numeric | grep -o '0.0.0.0:25', which only returns 0.0.0.0:25 |
Sorry, something went wrong.
Where is curl involved here? Isn't the exit status coming from the grep command otherwise?
I was not aware of that and you raise very valid points, thanks for pointing that out! 🙏
Is there value in that output being stored repeated in the healthcheck log? Shouldn't we just use grep -q for 0/1 exit status? As per the grep docs:
|
Sorry, something went wrong.
There was a problem hiding this comment.
Verified this check adjusted to interval: 1s:
$ docker inspect --format='{{json .State.Health}}' dms | jq
{
"Status": "healthy",
"FailingStreak": 0,
"Log": [
{
"Start": "2025-06-01T21:57:33.747428151Z",
"End": "2025-06-01T21:57:33.827584046Z",
"ExitCode": 1,
"Output": ""
},
{
"Start": "2025-06-01T21:57:34.828241261Z",
"End": "2025-06-01T21:57:34.919379591Z",
"ExitCode": 1,
"Output": ""
},
{
"Start": "2025-06-01T21:57:35.919784141Z",
"End": "2025-06-01T21:57:35.965090221Z",
"ExitCode": 0,
"Output": ""
},
{
"Start": "2025-06-01T21:57:36.965467119Z",
"End": "2025-06-01T21:57:37.012927453Z",
"ExitCode": 0,
"Output": ""
},
{
"Start": "2025-06-01T21:57:38.013727139Z",
"End": "2025-06-01T21:57:38.059783409Z",
"ExitCode": 0,
"Output": ""
}
]
}NOTE: Only the last 5 checks are stored in the log output, hence the reduced interval to confirm.
Sorry, something went wrong.
My bad. I was looking at another healthcheck example while writing. It was however just to explain the || exit 1 usage / best-practice.
That will work. Only disadvantage: when grep fails (return code 2) for whatever reason, it will happen silently. |
Sorry, something went wrong.
| # - NET_ADMIN | ||
| healthcheck: | ||
| test: "ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1" | ||
| test: "ss --listening --tcp | grep --silent ':smtp'" |
There was a problem hiding this comment.
Afaik our postfix listens only on IPv4. Therefore we could make it more explicit with:
| test: "ss --listening --tcp | grep --silent ':smtp'" | |
| test: "ss --listening --ipv4 --tcp | grep --silent ':smtp'" |
Sorry, something went wrong.
There was a problem hiding this comment.
I'm not sure if we should? If you had an IPv6 only container (I think this is possible in Docker now at least), the healthcheck could be agnostic to that.
DMS itself though does have a fair bit of 127.0.0.1 hard-coded I think instead of localhost, so it may not support IPv6 only out of the box 😅
If there is a good reason to specifically filter to IPv4 only though, we could do that. But I don't think there's any issues with also detecting listening on IPv6?
Sorry, something went wrong.
I assume the exit status of 2 becomes 1 in that case, but I'm not sure how to verify that. If grep is given an invalid arg or invalid filepath to search you still get an exit status of 2, despite --quiet / --silent. Presumably a valid command can error and instead of 2 you'd get 1? I suppose we could keep || exit 1 tacked on as a precaution? 🤷♂️ https://docs.docker.com/reference/dockerfile/#healthcheck
|
Sorry, something went wrong.
There was a problem hiding this comment.
Adding --ipv4 as suggested by @casperklein , should someone bring up IPv6 only DMS, we can discuss dropping it then 🤔
Adding back || exit 1 for broader compatibility. Some errors encountered by grep still return a 2 despite --silent/--quiet option being set.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Description
The current example healthcheck ss --listening --tcp | grep -P 'LISTEN.+:smtp' || exit 1 can be simplified to nc -z localhost 25 (our tests use this via a helper to wait on Postfix being ready), which effectively does the same check (that a service is listening on the port), but without the extra output or need to set an exit status (both of which could be resolved with grep -q).
The nc command is a bit more terser and direct though. The port 25 can be alternatively substituted for the service port smtp, (nc -z localhost smtp) just like the ss output displays (resolved via grep smtp /etc/services), but I figured most would be more familiar with the port number itself.
This has a benefit of less noisy healthcheck logs, which currently looks like this every 30 secs:
With nc instead:
Type of change