-
Notifications
You must be signed in to change notification settings - Fork 57
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
Labels
enhancement
New feature or request
Comments
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]>
Great idea @docwhat! Thanks for the PR, will give it a test and respond shortly. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 hasstatus == 1
.The text was updated successfully, but these errors were encountered: