INNER CODE UNIT · JavaScript
gracefulShutdown
riclolsen/json-scada · src/OPC-UA-Server/index.js:84
const gracefulShutdown = async (signal) => {
if (isShuttingDown) return
isShuttingDown = true
Log.log('Received ' + signal + ', shutting down...')
// force exit if a clean shutdown stalls (e.g. a hung endpoint)
const forceTimer = setTimeout(() => {
Log.log('Shutdown timed out, forcing exit.')
process.exit(1)
}, 10000)
if (forceTimer.unref) forceTimer.unref()
try {
await shutdownServers()
} catch (e) {
Log.log('Error shutting down OPC-UA server(s): ' + e)
}
try {
if (clientMongo) await clientMongo.close()
} catch (e) {