diff --git a/Sources/tart/Commands/Stop.swift b/Sources/tart/Commands/Stop.swift index 1ecc0d0..9c97c1e 100644 --- a/Sources/tart/Commands/Stop.swift +++ b/Sources/tart/Commands/Stop.swift @@ -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