Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial socket support draft #5081

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

angerman
Copy link

@angerman angerman commented Mar 2, 2023

This adds support for a utm.socket that can be used to list, start and stop VMs.

It allows controlling UTMData through a socket (if UTM is launched with --with-socket):

$ nc -U /Users/angerman/Library/Containers/com.utmapp.UTM/Data/utm.socket                                                  ~
UTM> list
UUID                                 Status   Name
FC379EA4-195C-499E-BDC9-066470BCA5C9 Stopped  macOS (blank backup)
UTM> start FC379EA4-195C-499E-BDC9-066470BCA5C9
FC379EA4-195C-499E-BDC9-066470BCA5C9 Stopped  macOS (blank backup)
UTM> list 
UUID                                 Status   Name
FC379EA4-195C-499E-BDC9-066470BCA5C9 Started  macOS (blank backup)
UTM> stop FC379EA4-195C-499E-BDC9-066470BCA5C9
FC379EA4-195C-499E-BDC9-066470BCA5C9 Started  macOS (blank backup)
UTM> list
UUID                                 Status   Name
FC379EA4-195C-499E-BDC9-066470BCA5C9 Stopped  macOS (blank backup)

The idea here is to launch UTM as a service, and then use the socket to communicate and control starting, stopping, ... VMs.

This is an initial draft, to start a discussion around whether or not such a feature is desirable, better approaches to it and so forth.

This adds support for a utm.socket that can be used to list, start and stop VMs.
@osy
Copy link
Contributor

osy commented Mar 2, 2023

FYI we had a socket command interface that was removed in favor of the scripting bridge interface d6fc3cd

@angerman
Copy link
Author

angerman commented Mar 2, 2023

FYI we had a socket command interface that was removed in favor of the scripting bridge interface d6fc3cd

That's interesting! Maybe I'm holding the scripting interface wrong, as I'm trying to figure out how to do this headless in an automated fashion. Utmctl doesn't like being run form within an ssh session.

@osy
Copy link
Contributor

osy commented Mar 2, 2023

The way apple events works depends on the GUI app running under some logged in user. So no, you can’t do it from just a ssh session. However, I don’t think you’ll get it working well with sockets either because of sandboxing. You’d need to launch the GUI somehow no matter what.

@angerman
Copy link
Author

angerman commented Mar 2, 2023

The way apple events works depends on the GUI app running under some logged in user. So no, you can’t do it from just a ssh session. However, I don’t think you’ll get it working well with sockets either because of sandboxing. You’d need to launch the GUI somehow no matter what.

Yes, I can launch UTM as a launch item for the automatically logged in user on the host. Building a different headless executable seems much more involved.

@angerman
Copy link
Author

angerman commented Mar 2, 2023

In essence, what I'd like is something like tart.run, without the restriction to HVF only, if that makes sense?

@osy
Copy link
Contributor

osy commented Mar 2, 2023

I think you may be better off using QEMU directly if you’re thinking about building a headless version.

@angerman
Copy link
Author

angerman commented Mar 2, 2023

osy, if it was for non-HVF applications yes. What I like a lot about UTM is

  • It provides a unified interface across QEMU + HVF
  • It can be used for initial bootstrap and interactive debugging of images.

I'm mostly interested in macOS on macOS. For Apple Silicon this is HVF, for Intel it's qemu. Using a common interface like utm has its appeal here. Just dealing with the graphical session is a bit annoying over high latency networks. If there is a way to run utmctl from a ssh shell that would pretty much solve all my needs right now, hence trying to sidestep the graphical login topic by using a unix socket for commandeering UTM. (To be fair though, it doesn't commandeer UTM directly right now, but just re-uses the UTMData structure and it's methods).

@ktprograms
Copy link
Contributor

FYI what you're referring to is Virtualization.framework, that's the higher level framework used for macOS-on-macOS on Apple Silicon

HVF is the low level hypervisor, similar to kvm on Linux

@angerman
Copy link
Author

After some experimentation here's what also works:

  • launch UTM in the graphical session.
  • launch Terminal, and tmux inside.
  • send commands to the tmux session from an ssh session.

Now that feels a bit convoluted, but allows us to obtain almost the same functionality like this without modifying utm.

.------- graphical session --------.  .- ssh session -.
|               .- Terminal.app -. |  |               |
| .-----.       | .--- tmux ------------------------. |
| | UTM<+--OSA--+-+>              utmctl            | |
| '-----'       | '---------------------------------' |
|               '----------------' |  |               |
'----------------------------------'  '---------------'

I wonder if adding a socket interface to utmctl (e.g. the ability to launch utmctl --daemon would be appreciated?)

The motivation is to control UTM from the command line of a non-graphical session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants