diff --git a/relay/index.js b/relay/index.js index 607def4..5f45b2f 100644 --- a/relay/index.js +++ b/relay/index.js @@ -3,7 +3,7 @@ const net = require('net'); const log = require('signale'); const { config } = require('./../package.json'); -title('relay'); +// title('relay'); // let connection = null; @@ -22,9 +22,7 @@ title('relay'); // })(); +log.debug('I AM RELAY!'); setTimeout(() => { - log.debug('this is a test output...') - setTimeout(() => { - log.debug('so we never process exit?') - }, 1000) + log.debug('this is a test output...'); }, 1000) \ No newline at end of file diff --git a/relay/service.js b/relay/service.js index e13e697..949474b 100644 --- a/relay/service.js +++ b/relay/service.js @@ -1,9 +1,10 @@ (() => { const log = require('signale'); -const { execSync } = require('child_process'); +const { execSync, spawn } = require('child_process'); const branch = 'master'; +let proc; -function update() { +setInterval(function update() { const remoteHash = execSync('git ls-remote https://github.com/marcus13345/valnet.git').toString().split(/[\t\n]/g)[0].trim(); const localHash = execSync(`git rev-parse ${branch}`).toString().trim(); if(remoteHash !== localHash) { @@ -13,18 +14,28 @@ function update() { execSync(`git fetch`); execSync(`git pull`); - log.info('restarting relay...'); - process.exit(2); + log.info('killing relay...'); + try { + proc.kill(); + } catch (e) { + log.error('failed to kill active relay...'); + log.error(e); + } } -} +}, 5000); +(function keepAlive() { + proc = spawn('node', ['relay'], { stdio: "inherit" }); + proc.on('exit', () => { + log.info('restarting relay...'); + setTimeout(() => { + keepAlive(); + }, 1000); + }) +})(); -require('./index.js'); - -setInterval(update, 5000); -