Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in a health check #10

Open
rossdargan opened this issue Aug 31, 2016 · 10 comments
Open

Add in a health check #10

rossdargan opened this issue Aug 31, 2016 · 10 comments

Comments

@rossdargan
Copy link

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

@toke
Copy link
Owner

toke commented Sep 1, 2016

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

@rossdargan
Copy link
Author

Ok, had a quick look. This won't be possible without including the client tools which I see you were not massively keen on: #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!

@toke
Copy link
Owner

toke commented Sep 1, 2016

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 toke mentioned this issue Sep 1, 2016
@rossdargan
Copy link
Author

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

@magnus919
Copy link

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?

@neurove
Copy link

neurove commented Sep 22, 2021

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

@Paraphraser
Copy link

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

@genieai-vikas
Copy link

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

@Paraphraser
Copy link

@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.

@neurove
Copy link

neurove commented Jan 11, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants