| 73 | let exitTimer: NodeJS.Timer | undefined = undefined; |
| 74 | |
| 75 | function setupExitTimer(): void { |
| 76 | const argName = '--clientProcessId'; |
| 77 | function runTimer(value: string): void { |
| 78 | try { |
| 79 | let processId = parseInt(value); |
| 80 | if (!isNaN(processId)) { |
| 81 | exitTimer = setInterval(() => { |
| 82 | try { |
| 83 | process.kill(processId, <any>0); |
| 84 | } catch (ex) { |
| 85 | // Parent process doesn't exist anymore. Exit the server. |
| 86 | process.exit(shutdownReceived ? 0 : 1); |
| 87 | } |
| 88 | }, 3000); |
| 89 | } |
| 90 | } catch (e) { |
| 91 | // Ignore errors; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | for (let i = 2; i < process.argv.length; i++) { |
| 96 | let arg = process.argv[i]; |
| 97 | if (arg === argName && i + 1 < process.argv.length) { |
| 98 | runTimer(process.argv[i + 1]); |
| 99 | return; |
| 100 | } else { |
| 101 | let args = arg.split('='); |
| 102 | if (args[0] === argName) { |
| 103 | runTimer(args[1]); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | setupExitTimer(); |
| 109 | |
| 110 | function null2Undefined<T>(value: T | null): T | undefined { |