From 44ba79d8f49edd81752063b27beb83b30f9eee31 Mon Sep 17 00:00:00 2001 From: Nuno Guedelha Date: Tue, 21 Sep 2021 04:21:37 +0200 Subject: [PATCH] WIP --- iCubTelemVizServer/iCubTelemVizServer.js | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/iCubTelemVizServer/iCubTelemVizServer.js b/iCubTelemVizServer/iCubTelemVizServer.js index a58555b..0246358 100644 --- a/iCubTelemVizServer/iCubTelemVizServer.js +++ b/iCubTelemVizServer/iCubTelemVizServer.js @@ -146,13 +146,13 @@ portRPCserver4sysCmds.onRead(function (cmdNparams) { }); // Start history and realtime servers -app.listen(portTelemetryRespOrigin, function () { +const telemServer = app.listen(portTelemetryRespOrigin, function () { console.log('ICubTelemetry History hosted at http://localhost:' + portTelemetryRespOrigin + '/history'); console.log('ICubTelemetry Realtime hosted at ws://localhost:' + portTelemetryRespOrigin + '/realtime'); }); // start the server! -http.listen(3000, function(){ +const consoleServer = http.listen(3000, function(){ console.log('listening on http://localhost:3000'); }); @@ -163,3 +163,27 @@ var ret = openMctServerHandler.setNvmVersion('v14.17.0'); console.log(ret.status); console.log(ret.message); openMctServerHandler.start(); + +function closeServers(signal) { + console.log('Received '+'SIGINT'+' ...'); + telemServer.close(() => { + console.log('iCub Telemetry Server Process terminated') + }) + consoleServer.close(() => { + console.log('Control Console Server Process terminated') + }) + openMctServerHandler.stop(); + process.exit(2); +} + +process.stdin.resume(); + +process.on('SIGINT', closeServers); +process.on('SIGTERM', closeServers); +process.on('SIGQUIT', closeServers); +process.on('SIGABRT', closeServers); + +console.log(process.pid); +console.log('Is the process.stdin a tty.ReadStream instance currently configured to operate as a raw device? '+process.stdin.isRaw+'!'); + +process.abort();