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

Check if service is still healthy #25

Open
Babalion opened this issue Dec 14, 2022 · 6 comments
Open

Check if service is still healthy #25

Babalion opened this issue Dec 14, 2022 · 6 comments
Labels
Docker Anything related to docker deployment enhancement New feature or request

Comments

@Babalion
Copy link

I suggest adding a health check to the docker-compose.yml file.
I can create a pull request for this, but I am unsure which would be the best way to check if the service is still healthy.

I am grateful for any help!

@moan0s
Copy link
Owner

moan0s commented Dec 14, 2022

Hi, do you have an example how this would look like? Sorry, never did this before

@Babalion
Copy link
Author

Babalion commented Dec 15, 2022

Of course!

In a common matrix-synapse docker-compose.yml one can add the following healthcheck:

healthcheck:
  test: ["CMD", "curl", "-fSs", "http://localhost:8008/health"]
  interval: 15s
  timeout: 5s
  retries: 3
  start_period: 5s

The command specified after test will be executed by the docker-daemon in the given interval.
After specified retries or timeout the docker-daemon will mark the service as unhealthy.
It is now up to the server administrator how to proceed with unhealthy services (for example send a notification, restart the container etc.).

So the question is, what command could be executed regularly in the bot container that succeeds when everything is fine and fails when something has gone wrong?

@moan0s moan0s added enhancement New feature or request Docker Anything related to docker deployment labels Dec 15, 2022
@moan0s
Copy link
Owner

moan0s commented Dec 15, 2022

Sounds good & sensible. Sadly with the framework that we use does not allow to easily implement a /health. I will try to think of something

@Babalion
Copy link
Author

We don't need a site like the /health in matrix-synapse.
Any shell command is fine. We can for example curl for a variable in a json response.
I've also seen healthchecks where they simply ping an arbitrary URL of the service.

So what would you check first, to be sure everything is fine?

Maybe the source code does not need to be changed at all...
What I noticed was, that the bot sometimes does not respond to a message. I had to restart the container then.
Maybe this is something one could check in a healthcheck?

@moan0s
Copy link
Owner

moan0s commented Jun 6, 2023

Sorry for the late response. I was thinking about this a lot and I think there is no easy way to check the status/health of the bot. The easiest I could think of, was to check the presence status of the bot like this

curl -H 'Authorization: Bearer syt_access_token_of_the_bot_itself'  https://synapse.hyteck.de/_matrix/client/v3/presence/@test-registration-bot:hyteck.de/status

whicht returns either {"presence":"online","last_active_ago":1957,"currently_active":true} or {"presence":"offline","last_active_ago":52746674}

@red0888
Copy link

red0888 commented Jun 17, 2023

Sorry for the late response. I was thinking about this a lot and I think there is no easy way to check the status/health of the bot. The easiest I could think of, was to check the presence status of the bot like this

curl -H 'Authorization: Bearer syt_access_token_of_the_bot_itself'  https://synapse.hyteck.de/_matrix/client/v3/presence/@test-registration-bot:hyteck.de/status

whicht returns either {"presence":"online","last_active_ago":1957,"currently_active":true} or {"presence":"offline","last_active_ago":52746674}

That works too imo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docker Anything related to docker deployment enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants