cirruslabs / tart

macOS and Linux VMs on Apple Silicon to use in CI and other automations
https://tart.run
Other
3.76k stars 106 forks source link

Graceful shutdown linux guest with tart run --no-graphics #659

Closed neowu closed 9 months ago

neowu commented 9 months ago

currently "tart stop vm" or ctrl-C sends SIGINT to PID of "tart run"

from source code, it cancels Run.swift->task, and eventually trigger VM.stop() function

which calls

try await self.virtualMachine.stop()

but with this way, it shutdown linux guest forcefully and caused "crash"

with some local experiment, i found requestStop() triggers a normal shutdown it works if i changes stop() function like following, it will print "guest has stopped the virtual machine" with ctrl+C

PS: the sleep part for debug purpose, i just need to wait few seconds to let linux finish shutdown

  @MainActor
  private func stop() async throws {
    if self.virtualMachine.canRequestStop {
      print("request VM to stop")
      try self.virtualMachine.requestStop()
    }
    print("sleep 10s")
    do {
      sleep(10)
    }
    print("end sleep")
  }

i am not sure what's the best way to solve this, like introduce some timeout after requestStop(), if failed then call stop() to force shutdown?

right now I am using "ssh -tt host sudo poweroff" to gracefully shutdown linux guest

edigaryev commented 9 months ago

Hello,

Are you using Tart from an automation tool, or manually through GUI?

In the latter case, you can request a graceful shutdown from ControlRequest Stop menu.

neowu commented 9 months ago

Thanks for the reply, i am using tart as lightweight vm tool for local development, mainly for linux vm and no GUI most of time. I can keep using "ssh -tt host sudo poweroff" instead of "tart stop host"