docker-mosquitto icon indicating copy to clipboard operation
docker-mosquitto copied to clipboard

Add in a health check

Open rossdargan opened this issue 8 years ago • 10 comments

Now that docker 1.12 supports health checks it would be great to see it added. I'm happy to do a PR if you want

rossdargan avatar Aug 31 '16 15:08 rossdargan

That would be a great addition. Feel free to contribute ;-)

toke avatar Sep 01 '16 07:09 toke

Ok, had a quick look. This won't be possible without including the client tools which I see you were not massively keen on: https://github.com/toke/docker-mosquitto/issues/8

So, two options, either this is a good enough reason to include the client tools, or I create a second DockerFile for a healthcheck version of this container.

Also need to find a way to pass through credentials to the healthcheck since I have mine protected via the config! Not sure how easy thats going to be!

rossdargan avatar Sep 01 '16 08:09 rossdargan

No problem. I just had no reasons for the client tools but if there is a reason I think it's correct to include them. So #8 and #10 are related and #8 can be closed then too.

toke avatar Sep 01 '16 12:09 toke

Just an update - close, but not quite reliable yet (it actually totally crashes docker somehow if the password isn't correct!)

https://stackoverflow.com/questions/39275666/script-to-check-mosquitto-is-healthy

rossdargan avatar Sep 01 '16 15:09 rossdargan

Sorry to poke an ancient issue, but I found this while googling to see if there were any plans to add a healthcheck to this image. Is this still sort of out there on the long-term wishlist?

magnus919 avatar Nov 30 '20 14:11 magnus919

I added this healthcheck for the mosquitto docker container on my docker-compose.yaml

healthcheck: test: ["CMD-SHELL", "mosquitto_sub -h $MQTT_HOST -p $MQTT_POST -t '#' -u $MQTT_USER -P $MQTT_PASSWORD -C 1 | grep -v Error || exit 1"] interval: 10s timeout: 5s retries: 5

neurove avatar Sep 22 '21 12:09 neurove

@neurove - your post started me thinking. What do you think about IOTstack issue 415 as an expansion on your idea?

Paraphraser avatar Sep 29 '21 07:09 Paraphraser

@neurove I tried your healthcheck but getting this error: Unable to connect (Lookup error.).

genieai-vikas avatar Nov 14 '21 11:11 genieai-vikas

@genieai-vikas maybe take a look at SensorsIot/IOTstack and, in particular iotstack_healthcheck.sh.

The IOTstack solution started with the basic idea from @neurove but grew. It has been "in production" with IOTstack for the last month and no issues have come in yet (touch wood).

There is also some documentation that may prove useful.

Paraphraser avatar Nov 14 '21 12:11 Paraphraser

For documentation purposes, I changed the healthcheck to:

healthcheck: test: ["CMD-SHELL", "mosquitto_sub -h $MQTT_HOST -p $MQTT_POST -t '#' -u $MQTT_USER -P $MQTT_PASSWORD -E -i healthcheck | grep -v Error || exit 1"] nterval: 10s timeout: 5s retries: 5

using -E instead of -C 1 exits immediately after subscribing instead of waiting for a message being published

neurove avatar Jan 11 '23 17:01 neurove