mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
better shutdown logic to capture waveapp logs from wavesrv shutdown (#931)
This commit is contained in:
parent
76ccd83c5c
commit
545a914c4c
@ -65,6 +65,7 @@ func doShutdown(reason string) {
|
|||||||
watcher.Close()
|
watcher.Close()
|
||||||
}
|
}
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
log.Printf("shutdown complete\n")
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import * as util from "util";
|
|||||||
import winston from "winston";
|
import winston from "winston";
|
||||||
import { initGlobal } from "../frontend/app/store/global";
|
import { initGlobal } from "../frontend/app/store/global";
|
||||||
import * as services from "../frontend/app/store/services";
|
import * as services from "../frontend/app/store/services";
|
||||||
import { initElectronWshrpc } from "../frontend/app/store/wshrpcutil";
|
import { initElectronWshrpc, shutdownWshrpc } from "../frontend/app/store/wshrpcutil";
|
||||||
import { WSServerEndpointVarName, WebServerEndpointVarName, getWebServerEndpoint } from "../frontend/util/endpoints";
|
import { WSServerEndpointVarName, WebServerEndpointVarName, getWebServerEndpoint } from "../frontend/util/endpoints";
|
||||||
import { fetch } from "../frontend/util/fetchutil";
|
import { fetch } from "../frontend/util/fetchutil";
|
||||||
import * as keyutil from "../frontend/util/keyutil";
|
import * as keyutil from "../frontend/util/keyutil";
|
||||||
@ -41,6 +41,8 @@ import { configureAutoUpdater, updater } from "./updater";
|
|||||||
const electronApp = electron.app;
|
const electronApp = electron.app;
|
||||||
let WaveVersion = "unknown"; // set by WAVESRV-ESTART
|
let WaveVersion = "unknown"; // set by WAVESRV-ESTART
|
||||||
let WaveBuildTime = 0; // set by WAVESRV-ESTART
|
let WaveBuildTime = 0; // set by WAVESRV-ESTART
|
||||||
|
let forceQuit = false;
|
||||||
|
let isWaveSrvDead = false;
|
||||||
|
|
||||||
const WaveAppPathVarName = "WAVETERM_APP_PATH";
|
const WaveAppPathVarName = "WAVETERM_APP_PATH";
|
||||||
const WaveSrvReadySignalPidVarName = "WAVETERM_READY_SIGNAL_PID";
|
const WaveSrvReadySignalPidVarName = "WAVETERM_READY_SIGNAL_PID";
|
||||||
@ -167,10 +169,12 @@ function runWaveSrv(): Promise<boolean> {
|
|||||||
env: envCopy,
|
env: envCopy,
|
||||||
});
|
});
|
||||||
proc.on("exit", (e) => {
|
proc.on("exit", (e) => {
|
||||||
if (globalIsQuitting || updater?.status == "installing") {
|
if (updater?.status == "installing") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log("wavesrv exited, shutting down");
|
console.log("wavesrv exited, shutting down");
|
||||||
|
forceQuit = true;
|
||||||
|
isWaveSrvDead = true;
|
||||||
electronApp.quit();
|
electronApp.quit();
|
||||||
});
|
});
|
||||||
proc.on("spawn", (e) => {
|
proc.on("spawn", (e) => {
|
||||||
@ -935,9 +939,30 @@ electronApp.on("window-all-closed", () => {
|
|||||||
electronApp.quit();
|
electronApp.quit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
electronApp.on("before-quit", () => {
|
electronApp.on("before-quit", (e) => {
|
||||||
globalIsQuitting = true;
|
globalIsQuitting = true;
|
||||||
updater?.stop();
|
updater?.stop();
|
||||||
|
waveSrvProc?.kill("SIGINT");
|
||||||
|
shutdownWshrpc();
|
||||||
|
if (forceQuit) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
const allWindows = electron.BrowserWindow.getAllWindows();
|
||||||
|
for (const window of allWindows) {
|
||||||
|
window.hide();
|
||||||
|
}
|
||||||
|
if (isWaveSrvDead) {
|
||||||
|
console.log("wavesrv is dead, quitting immediately");
|
||||||
|
forceQuit = true;
|
||||||
|
electronApp.quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
console.log("waiting for wavesrv to exit...");
|
||||||
|
forceQuit = true;
|
||||||
|
electronApp.quit();
|
||||||
|
}, 3000);
|
||||||
});
|
});
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
console.log("Caught SIGINT, shutting down");
|
console.log("Caught SIGINT, shutting down");
|
||||||
|
@ -44,6 +44,7 @@ class WSControl {
|
|||||||
baseHostPort: string;
|
baseHostPort: string;
|
||||||
lastReconnectTime: number = 0;
|
lastReconnectTime: number = 0;
|
||||||
eoOpts: ElectronOverrideOpts;
|
eoOpts: ElectronOverrideOpts;
|
||||||
|
noReconnect: boolean = false;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
baseHostPort: string,
|
baseHostPort: string,
|
||||||
@ -59,8 +60,13 @@ class WSControl {
|
|||||||
setInterval(this.sendPing.bind(this), 5000);
|
setInterval(this.sendPing.bind(this), 5000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shutdown() {
|
||||||
|
this.noReconnect = true;
|
||||||
|
this.wsConn.close();
|
||||||
|
}
|
||||||
|
|
||||||
connectNow(desc: string) {
|
connectNow(desc: string) {
|
||||||
if (this.open) {
|
if (this.open || this.noReconnect) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.lastReconnectTime = Date.now();
|
this.lastReconnectTime = Date.now();
|
||||||
@ -82,6 +88,9 @@ class WSControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reconnect(forceClose?: boolean) {
|
reconnect(forceClose?: boolean) {
|
||||||
|
if (this.noReconnect) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (this.open) {
|
if (this.open) {
|
||||||
if (forceClose) {
|
if (forceClose) {
|
||||||
this.wsConn.close(); // this will force a reconnect
|
this.wsConn.close(); // this will force a reconnect
|
||||||
|
@ -128,6 +128,10 @@ function initElectronWshrpc(electronClient: WshClient, eoOpts: ElectronOverrideO
|
|||||||
addWSReconnectHandler(wpsReconnectHandler);
|
addWSReconnectHandler(wpsReconnectHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shutdownWshrpc() {
|
||||||
|
globalWS?.shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
function initWshrpc(windowId: string): WSControl {
|
function initWshrpc(windowId: string): WSControl {
|
||||||
DefaultRouter = new WshRouter(new UpstreamWshRpcProxy());
|
DefaultRouter = new WshRouter(new UpstreamWshRpcProxy());
|
||||||
const handleFn = (event: WSEventType) => {
|
const handleFn = (event: WSEventType) => {
|
||||||
@ -163,5 +167,6 @@ export {
|
|||||||
sendRpcCommand,
|
sendRpcCommand,
|
||||||
sendRpcResponse,
|
sendRpcResponse,
|
||||||
sendWSCommand,
|
sendWSCommand,
|
||||||
|
shutdownWshrpc,
|
||||||
WindowRpcClient,
|
WindowRpcClient,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user