This repository has been archived on 2023-11-14. You can view files and clone it, but cannot push or open issues/pull-requests.
valnet/relay/service.js

49 lines
953 B
JavaScript
Raw Normal View History

2020-11-11 19:38:39 -05:00
(() => {
2020-11-11 21:02:58 -05:00
const log = require('signale');
const { execSync, spawn } = require('child_process');
2020-11-11 19:38:39 -05:00
const branch = 'master';
let proc;
2020-11-11 19:38:39 -05:00
setInterval(function update() {
2020-11-11 21:02:58 -05:00
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) {
log.info('remote hash:', remoteHash);
log.info('local hash: ', localHash);
2020-11-11 21:49:42 -05:00
log.info('attempting to fetch new version');
2020-11-11 21:42:23 -05:00
2020-11-11 21:49:42 -05:00
execSync(`git fetch`);
execSync(`git pull`);
log.info('killing relay...');
try {
proc.kill();
} catch (e) {
log.error('failed to kill active relay...');
log.error(e);
}
2020-11-11 21:02:58 -05:00
}
}, 5000);
2020-11-11 19:38:39 -05:00
(function keepAlive() {
proc = spawn('node', ['relay'], { stdio: "inherit" });
2020-11-11 19:38:39 -05:00
proc.on('exit', () => {
2020-11-11 22:05:02 -05:00
log.info('relay exitted, restarting...');
setTimeout(() => {
keepAlive();
}, 1000);
})
})();
2020-11-11 19:38:39 -05:00
})();