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

Please add HEALTHCHECK #4

Closed
docwhat opened this issue Oct 19, 2019 · 2 comments
Closed

Please add HEALTHCHECK #4

docwhat opened this issue Oct 19, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@docwhat
Copy link

docwhat commented Oct 19, 2019

To ensure that the docker container starts up (and stays up) correctly I would like a HEALTHCHECK added.

It could be done by using a Node script to check /info to ensure it has status == 1.

@docwhat
Copy link
Author

docwhat commented Oct 20, 2019

I think this should work using stock NodeJS stuff.

I based it on Anthony Mineo's blog post: Docker Healthcheck for your Node.js App.

const http = require("http");
const options = {
  host: "0.0.0.0",
  port: 8080,
  method: "GET",
  path: "/info",
  timeout: 2000
};

const healthCheck = http.request(options, res => {
  let body = "";

  res.setEncoding("utf8");
  res.on("data", chunk => (body += chunk));
  res.on("end", () => {
    if (res.statusCode === 200) {
      let payload = JSON.parse(body);
      if (payload.status === 1) {
        console.log(`HEALTHCHECK (v${payload.version}): online`);
        process.exit(0);
      } else if (payload.status === 2) {
        console.log(`HEALTHCHECK (v${payload.version}): offline`);
      } else if (payload.status === 3) {
        console.log(
          `HEALTHCHECK (v${payload.version}): not accepting new syncs`
        );
      } else {
        console.log(
          `HEALTHCHECK (v${payload.version}): unknown (status: ${payload.status})`
        );
      }
    } else {
      console.log(`HEALTHCHECK: ${res.statusCode}`);
    }
    process.exit(1);
  });
});

healthCheck.on("error", function(err) {
  console.error(`ERROR ${err}`);
  process.exit(1);
});

healthCheck.end();

docwhat added a commit to docwhat/api-docker that referenced this issue Oct 20, 2019
fixes issue xbrowsersync#4

Signed-off-by: Christian Höltje <[email protected]>
@nero120 nero120 added the enhancement New feature or request label Oct 21, 2019
@nero120
Copy link
Member

nero120 commented Oct 21, 2019

Great idea @docwhat! Thanks for the PR, will give it a test and respond shortly.

@nero120 nero120 closed this as completed in 024b624 Apr 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants