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

Allow signals to stop server #181

Merged
merged 5 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,10 @@ const startAgent = ( logger ) => {
/**
*
*/
var server
if (agent_scheme === 'https') {

https.createServer({
server = https.createServer({
cert: fs.readFileSync(certificate_path),
key: fs.readFileSync(key_path),
}, app).listen(agent_listen_port, "0.0.0.0", function() {
Expand All @@ -520,14 +521,36 @@ const startAgent = ( logger ) => {
}
else {

http.createServer({
server = http.createServer({
}, app).listen(agent_listen_port, "0.0.0.0", function() {
logger.info({message: 'listening', port: agent_listen_port, scheme: agent_scheme});
});

}
/** -------------------------------------------------------------------------------------------------- */


// The signals we want to handle
// NOTE: although it is tempting, the SIGKILL signal (9) cannot be intercepted and handled
var signals = {
'SIGHUP': 1,
'SIGINT': 2,
'SIGTERM': 15
};
// Do any necessary shutdown logic for our application here
const shutdown = (signal, value) => {
console.log("shutdown!");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change these console.log to logger.info please

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

server.close(() => {
console.log(`server stopped by ${signal} with value ${value}`);
process.exit(128 + value);
});
};
// Create a listener for each of the signals that we want to handle
Object.keys(signals).forEach((signal) => {
process.on(signal, () => {
console.log(`process received a ${signal} signal`);
shutdown(signal, signals[signal]);
});
});
};


Expand Down
4 changes: 2 additions & 2 deletions zha-docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cat <<-EOF
EOF

if [ -z ${ZITI_AGENT_LOG_PATH} ]; then
NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem node index.js
NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem exec node index.js
else
NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem node index.js >> "${ZITI_AGENT_LOG_PATH}" 2>&1
NODE_EXTRA_CA_CERTS=node_modules/node_extra_ca_certs_mozilla_bundle/ca_bundle/ca_intermediate_root_bundle.pem exec node index.js >> "${ZITI_AGENT_LOG_PATH}" 2>&1
fi
Loading