mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +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()
|
||||
}
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
log.Printf("shutdown complete\n")
|
||||
os.Exit(0)
|
||||
})
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ import * as util from "util";
|
||||
import winston from "winston";
|
||||
import { initGlobal } from "../frontend/app/store/global";
|
||||
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 { fetch } from "../frontend/util/fetchutil";
|
||||
import * as keyutil from "../frontend/util/keyutil";
|
||||
@ -41,6 +41,8 @@ import { configureAutoUpdater, updater } from "./updater";
|
||||
const electronApp = electron.app;
|
||||
let WaveVersion = "unknown"; // set by WAVESRV-ESTART
|
||||
let WaveBuildTime = 0; // set by WAVESRV-ESTART
|
||||
let forceQuit = false;
|
||||
let isWaveSrvDead = false;
|
||||
|
||||
const WaveAppPathVarName = "WAVETERM_APP_PATH";
|
||||
const WaveSrvReadySignalPidVarName = "WAVETERM_READY_SIGNAL_PID";
|
||||
@ -167,10 +169,12 @@ function runWaveSrv(): Promise<boolean> {
|
||||
env: envCopy,
|
||||
});
|
||||
proc.on("exit", (e) => {
|
||||
if (globalIsQuitting || updater?.status == "installing") {
|
||||
if (updater?.status == "installing") {
|
||||
return;
|
||||
}
|
||||
console.log("wavesrv exited, shutting down");
|
||||
forceQuit = true;
|
||||
isWaveSrvDead = true;
|
||||
electronApp.quit();
|
||||
});
|
||||
proc.on("spawn", (e) => {
|
||||
@ -935,9 +939,30 @@ electronApp.on("window-all-closed", () => {
|
||||
electronApp.quit();
|
||||
}
|
||||
});
|
||||
electronApp.on("before-quit", () => {
|
||||
electronApp.on("before-quit", (e) => {
|
||||
globalIsQuitting = true;
|
||||
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", () => {
|
||||
console.log("Caught SIGINT, shutting down");
|
||||
|
@ -44,6 +44,7 @@ class WSControl {
|
||||
baseHostPort: string;
|
||||
lastReconnectTime: number = 0;
|
||||
eoOpts: ElectronOverrideOpts;
|
||||
noReconnect: boolean = false;
|
||||
|
||||
constructor(
|
||||
baseHostPort: string,
|
||||
@ -59,8 +60,13 @@ class WSControl {
|
||||
setInterval(this.sendPing.bind(this), 5000);
|
||||
}
|
||||
|
||||
shutdown() {
|
||||
this.noReconnect = true;
|
||||
this.wsConn.close();
|
||||
}
|
||||
|
||||
connectNow(desc: string) {
|
||||
if (this.open) {
|
||||
if (this.open || this.noReconnect) {
|
||||
return;
|
||||
}
|
||||
this.lastReconnectTime = Date.now();
|
||||
@ -82,6 +88,9 @@ class WSControl {
|
||||
}
|
||||
|
||||
reconnect(forceClose?: boolean) {
|
||||
if (this.noReconnect) {
|
||||
return;
|
||||
}
|
||||
if (this.open) {
|
||||
if (forceClose) {
|
||||
this.wsConn.close(); // this will force a reconnect
|
||||
|
@ -128,6 +128,10 @@ function initElectronWshrpc(electronClient: WshClient, eoOpts: ElectronOverrideO
|
||||
addWSReconnectHandler(wpsReconnectHandler);
|
||||
}
|
||||
|
||||
function shutdownWshrpc() {
|
||||
globalWS?.shutdown();
|
||||
}
|
||||
|
||||
function initWshrpc(windowId: string): WSControl {
|
||||
DefaultRouter = new WshRouter(new UpstreamWshRpcProxy());
|
||||
const handleFn = (event: WSEventType) => {
|
||||
@ -163,5 +167,6 @@ export {
|
||||
sendRpcCommand,
|
||||
sendRpcResponse,
|
||||
sendWSCommand,
|
||||
shutdownWshrpc,
|
||||
WindowRpcClient,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user