docker-mosquitto
docker-mosquitto copied to clipboard
Add in a health check
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
That would be a great addition. Feel free to contribute ;-)
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!
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.
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
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?
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 - your post started me thinking. What do you think about IOTstack issue 415 as an expansion on your idea?
@neurove I tried your healthcheck but getting this error:
Unable to connect (Lookup error.).
@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.
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