v0.20.1: cleanup restart
This commit is contained in:
parent
a6527d30a6
commit
42d558b85e
|
@ -480,26 +480,32 @@ function serveControlsHelper() {
|
|||
}
|
||||
|
||||
function restart() {
|
||||
console.info("[telebitd.js] server closing...");
|
||||
state.keepAlive.state = false;
|
||||
if (myRemote) {
|
||||
myRemote.end();
|
||||
myRemote.on('end', respondAndClose);
|
||||
// failsafe
|
||||
setTimeout(function () {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({ success: true }));
|
||||
setTimeout(function () {
|
||||
process.exit(33);
|
||||
}, 500);
|
||||
console.info("[telebitd.js] closing too slowly, force quit");
|
||||
respondAndClose();
|
||||
}, 5 * 1000);
|
||||
} else {
|
||||
respondAndClose();
|
||||
}
|
||||
|
||||
if (myRemote) { myRemote.end(); }
|
||||
controlServer.close(function () {
|
||||
function respondAndClose() {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify({ success: true }));
|
||||
|
||||
controlServer.close(function () {
|
||||
console.info("[telebitd.js] server closed");
|
||||
setTimeout(function () {
|
||||
// system daemon will restart the process
|
||||
process.exit(22); // use non-success exit code
|
||||
}, 500);
|
||||
}, 100);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function invalidConfig() {
|
||||
res.statusCode = 400;
|
||||
|
@ -689,8 +695,10 @@ function serveControls() {
|
|||
}
|
||||
|
||||
console.info("[info] connecting with stored token");
|
||||
return safeStartTelebitRemote().catch(function (/*err*/) {
|
||||
return safeStartTelebitRemote().catch(function (err) {
|
||||
// ignore, it'll keep looping anyway
|
||||
console.warn("[debug] error that (supposedly) shouldn't matter:");
|
||||
console.warn(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -806,18 +814,19 @@ function safeStartTelebitRemote(forceOn) {
|
|||
// this won't restart either
|
||||
trPromise = rawStartTelebitRemote(state.keepAlive);
|
||||
trPromise.then(function () {
|
||||
//console.log("I'm RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
console.log("[debug] success on raw start, keepAlive = true");
|
||||
state.keepAlive.state = true;
|
||||
trPromise = null;
|
||||
}).catch(function () {
|
||||
//console.log("I FAILED US ALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
console.log("[debug] failure on raw start, { keepAlive = true }");
|
||||
// this will restart
|
||||
state.keepAlive = { state: true };
|
||||
trPromise = rawStartTelebitRemote(state.keepAlive);
|
||||
trPromise.then(function () {
|
||||
console.log("[debug] success on 2nd start keepAlive:", state.keepAlive.state);
|
||||
trPromise = null;
|
||||
}).catch(function () {
|
||||
//console.log('DEBUG state.keepAlive turned off and remote quit');
|
||||
console.log("[debug] failure on 2nd start. keepAlive", state.keepAlive.state);
|
||||
trPromise = null;
|
||||
});
|
||||
});
|
||||
|
|
|
@ -472,12 +472,12 @@ function TelebitRemote(state) {
|
|||
priv.timeoutId = null;
|
||||
var machine = Packer.create(packerHandlers);
|
||||
|
||||
console.info("[connect] '" + (state.wss || state.relay) + "'");
|
||||
console.info("[telebit:lib/remote.js] [connect] '" + (state.wss || state.relay) + "'");
|
||||
var tunnelUrl = (state.wss || state.relay).replace(/\/$/, '') + '/'; // + auth;
|
||||
wstunneler = new WebSocket(tunnelUrl, { rejectUnauthorized: !state.insecure });
|
||||
// XXXXXX
|
||||
wstunneler.on('open', function () {
|
||||
console.info("[open] connected to '" + (state.wss || state.relay) + "'");
|
||||
console.info("[telebit:lib/remote.js] [open] connected to '" + (state.wss || state.relay) + "'");
|
||||
me.emit('connect');
|
||||
priv.refreshTimeout();
|
||||
priv.timeoutId = setTimeout(priv.checkTimeout, activityTimeout);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "telebit",
|
||||
"version": "0.20.0-wip",
|
||||
"version": "0.20.1-wip",
|
||||
"description": "Break out of localhost. Connect to any device from anywhere over any tcp port or securely in a browser. A secure tunnel. A poor man's reverse VPN.",
|
||||
"main": "lib/remote.js",
|
||||
"files": [
|
||||
|
|
Loading…
Reference in New Issue