Skip to content

Commit

Permalink
Support stopping of suspended VMs (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov authored Jul 7, 2023
1 parent d2ed4ef commit e8dbb86
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Sources/tart/Commands/Stop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e8dbb86

Please sign in to comment.