qemu: cleanup/fix reset
This commit is contained in:
@@ -36,7 +36,6 @@ export class QemuVM extends EventEmitter {
|
|||||||
private qmpFailCount = 0;
|
private qmpFailCount = 0;
|
||||||
|
|
||||||
private qemuProcess: ExecaChildProcess | null = null;
|
private qemuProcess: ExecaChildProcess | null = null;
|
||||||
private qemuRunning = false;
|
|
||||||
|
|
||||||
private display: QemuDisplay;
|
private display: QemuDisplay;
|
||||||
private definition: QemuVmDefinition;
|
private definition: QemuVmDefinition;
|
||||||
@@ -54,12 +53,12 @@ export class QemuVM extends EventEmitter {
|
|||||||
|
|
||||||
async Start() {
|
async Start() {
|
||||||
// Don't start while either trying to start or starting.
|
// Don't start while either trying to start or starting.
|
||||||
if (this.state == VMState.Started || this.state == VMState.Starting) return;
|
//if (this.state == VMState.Started || this.state == VMState.Starting) return;
|
||||||
|
if(this.qemuProcess) return;
|
||||||
|
|
||||||
let cmd = this.definition.command;
|
let cmd = this.definition.command;
|
||||||
|
|
||||||
// build additional command line statements to enable qmp/vnc over unix sockets
|
// Build additional command line statements to enable qmp/vnc over unix sockets
|
||||||
// FIXME: Still use TCP if on Windows.
|
|
||||||
if (!this.addedAdditionalArguments) {
|
if (!this.addedAdditionalArguments) {
|
||||||
cmd += ' -no-shutdown';
|
cmd += ' -no-shutdown';
|
||||||
if (this.definition.snapshot) cmd += ' -snapshot';
|
if (this.definition.snapshot) cmd += ' -snapshot';
|
||||||
@@ -101,8 +100,13 @@ export class QemuVM extends EventEmitter {
|
|||||||
// let code know the VM is going to reset
|
// let code know the VM is going to reset
|
||||||
this.emit('reset');
|
this.emit('reset');
|
||||||
|
|
||||||
// Do magic.
|
if(this.qemuProcess !== null) {
|
||||||
await this.StopQemu();
|
// Do magic.
|
||||||
|
await this.StopQemu();
|
||||||
|
} else {
|
||||||
|
// N.B we always get here when addl. arguments are added
|
||||||
|
await this.StartQemu(this.definition.command);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async QmpCommand(command: string, args: any | null): Promise<any> {
|
async QmpCommand(command: string, args: any | null): Promise<any> {
|
||||||
@@ -150,9 +154,8 @@ export class QemuVM extends EventEmitter {
|
|||||||
this.state = state;
|
this.state = state;
|
||||||
this.emit('statechange', this.state);
|
this.emit('statechange', this.state);
|
||||||
|
|
||||||
// reset some state when starting the vm back up
|
// reset QMP fail count when the VM is (re)starting or stopped
|
||||||
// to avoid potentional issues.
|
if(this.state == VMState.Stopped || this.state == VMState.Starting) {
|
||||||
if(this.state == VMState.Starting) {
|
|
||||||
this.qmpFailCount = 0;
|
this.qmpFailCount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,14 +180,12 @@ export class QemuVM extends EventEmitter {
|
|||||||
|
|
||||||
this.qemuProcess.on('spawn', async () => {
|
this.qemuProcess.on('spawn', async () => {
|
||||||
self.VMLog().Info("QEMU started");
|
self.VMLog().Info("QEMU started");
|
||||||
self.qemuRunning = true;
|
|
||||||
await Shared.Sleep(500);
|
await Shared.Sleep(500);
|
||||||
await self.ConnectQmp();
|
await self.ConnectQmp();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.qemuProcess.on('exit', async (code) => {
|
this.qemuProcess.on('exit', async (code) => {
|
||||||
self.VMLog().Info("QEMU process exited");
|
self.VMLog().Info("QEMU process exited");
|
||||||
self.qemuRunning = false;
|
|
||||||
|
|
||||||
|
|
||||||
// this should be being done anways but it's very clearly not sometimes so
|
// this should be being done anways but it's very clearly not sometimes so
|
||||||
@@ -222,7 +223,10 @@ export class QemuVM extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async StopQemu() {
|
private async StopQemu() {
|
||||||
if (this.qemuRunning == true) this.qemuProcess?.kill('SIGTERM');
|
if (this.qemuProcess) {
|
||||||
|
this.qemuProcess?.kill('SIGTERM');
|
||||||
|
this.qemuProcess = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async ConnectQmp() {
|
private async ConnectQmp() {
|
||||||
@@ -291,7 +295,6 @@ export class QemuVM extends EventEmitter {
|
|||||||
private async DisconnectDisplay() {
|
private async DisconnectDisplay() {
|
||||||
try {
|
try {
|
||||||
this.display?.Disconnect();
|
this.display?.Disconnect();
|
||||||
//this.display = null; // disassociate with that display object.
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// oh well lol
|
// oh well lol
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user