Support stopping of suspended VMs (#541)

This commit is contained in:
Fedor Korotkov
2023-07-07 13:38:34 +04:00
committed by GitHub
parent d2ed4ef801
commit e8dbb86fc0
+15
View File
@@ -14,6 +14,21 @@ struct Stop: AsyncParsableCommand {
func run() async throws {
let vmDir = try VMStorageLocal().open(name)
switch try vmDir.state() {
case "suspended":
try stopSuspended(vmDir)
case "running":
try await stopRunning(vmDir)
default:
return
}
}
func stopSuspended(_ vmDir: VMDirectory) throws {
try? FileManager.default.removeItem(at: vmDir.stateURL)
}
func stopRunning(_ vmDir: VMDirectory) async throws {
let lock = try PIDLock(lockURL: vmDir.configURL)
// Find the VM's PID