v0.20.1: cleanup restart
This commit is contained in:
parent
a6527d30a6
commit
42d558b85e
|
@ -480,25 +480,31 @@ function serveControlsHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function restart() {
|
function restart() {
|
||||||
// failsafe
|
console.info("[telebitd.js] server closing...");
|
||||||
setTimeout(function () {
|
state.keepAlive.state = false;
|
||||||
|
if (myRemote) {
|
||||||
|
myRemote.end();
|
||||||
|
myRemote.on('end', respondAndClose);
|
||||||
|
// failsafe
|
||||||
|
setTimeout(function () {
|
||||||
|
console.info("[telebitd.js] closing too slowly, force quit");
|
||||||
|
respondAndClose();
|
||||||
|
}, 5 * 1000);
|
||||||
|
} else {
|
||||||
|
respondAndClose();
|
||||||
|
}
|
||||||
|
|
||||||
|
function respondAndClose() {
|
||||||
res.setHeader('Content-Type', 'application/json');
|
res.setHeader('Content-Type', 'application/json');
|
||||||
res.end(JSON.stringify({ success: true }));
|
res.end(JSON.stringify({ success: true }));
|
||||||
setTimeout(function () {
|
controlServer.close(function () {
|
||||||
process.exit(33);
|
console.info("[telebitd.js] server closed");
|
||||||
}, 500);
|
setTimeout(function () {
|
||||||
}, 5 * 1000);
|
// system daemon will restart the process
|
||||||
|
process.exit(22); // use non-success exit code
|
||||||
if (myRemote) { myRemote.end(); }
|
}, 100);
|
||||||
controlServer.close(function () {
|
});
|
||||||
res.setHeader('Content-Type', 'application/json');
|
}
|
||||||
res.end(JSON.stringify({ success: true }));
|
|
||||||
|
|
||||||
setTimeout(function () {
|
|
||||||
// system daemon will restart the process
|
|
||||||
process.exit(22); // use non-success exit code
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function invalidConfig() {
|
function invalidConfig() {
|
||||||
|
@ -689,8 +695,10 @@ function serveControls() {
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info("[info] connecting with stored token");
|
console.info("[info] connecting with stored token");
|
||||||
return safeStartTelebitRemote().catch(function (/*err*/) {
|
return safeStartTelebitRemote().catch(function (err) {
|
||||||
// ignore, it'll keep looping anyway
|
// 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
|
// this won't restart either
|
||||||
trPromise = rawStartTelebitRemote(state.keepAlive);
|
trPromise = rawStartTelebitRemote(state.keepAlive);
|
||||||
trPromise.then(function () {
|
trPromise.then(function () {
|
||||||
//console.log("I'm RIGHT HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
console.log("[debug] success on raw start, keepAlive = true");
|
||||||
state.keepAlive.state = true;
|
state.keepAlive.state = true;
|
||||||
trPromise = null;
|
trPromise = null;
|
||||||
}).catch(function () {
|
}).catch(function () {
|
||||||
//console.log("I FAILED US ALL!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
console.log("[debug] failure on raw start, { keepAlive = true }");
|
||||||
// this will restart
|
// this will restart
|
||||||
state.keepAlive = { state: true };
|
state.keepAlive = { state: true };
|
||||||
trPromise = rawStartTelebitRemote(state.keepAlive);
|
trPromise = rawStartTelebitRemote(state.keepAlive);
|
||||||
trPromise.then(function () {
|
trPromise.then(function () {
|
||||||
|
console.log("[debug] success on 2nd start keepAlive:", state.keepAlive.state);
|
||||||
trPromise = null;
|
trPromise = null;
|
||||||
}).catch(function () {
|
}).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;
|
trPromise = null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -472,12 +472,12 @@ function TelebitRemote(state) {
|
||||||
priv.timeoutId = null;
|
priv.timeoutId = null;
|
||||||
var machine = Packer.create(packerHandlers);
|
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;
|
var tunnelUrl = (state.wss || state.relay).replace(/\/$/, '') + '/'; // + auth;
|
||||||
wstunneler = new WebSocket(tunnelUrl, { rejectUnauthorized: !state.insecure });
|
wstunneler = new WebSocket(tunnelUrl, { rejectUnauthorized: !state.insecure });
|
||||||
// XXXXXX
|
// XXXXXX
|
||||||
wstunneler.on('open', function () {
|
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');
|
me.emit('connect');
|
||||||
priv.refreshTimeout();
|
priv.refreshTimeout();
|
||||||
priv.timeoutId = setTimeout(priv.checkTimeout, activityTimeout);
|
priv.timeoutId = setTimeout(priv.checkTimeout, activityTimeout);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "telebit",
|
"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.",
|
"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",
|
"main": "lib/remote.js",
|
||||||
"files": [
|
"files": [
|
||||||
|
|
Loading…
Reference in New Issue