The exec API route

2 questions here:

  1. How would i go about using the exec route with interactive, what does it return, and how can i use that to interact with stdin and stdout, as the API documentation is not very clear on this.

  2. How would i go about executing a command and then waiting until that command has finished running in the container?

What language are you doing that from?

When interactive, a single bi-directional websocket is used for data, alongside the control websocket to send things like signals and window resize events.

When non-interactive, you instead get 3 websockets for data, one for each of stdin, stdout and stderr as well as the control socket.

As you want interactive, you’d to connect to the single data websocket, write to send to stdin, read to get stdout/stderr. If you need to differentiate between stdout and stderr, then you want non-interactive instead.

As for knowing when done, you want a thread/goroutine to wait for the background operation.
In Go, calling ExecContainer will return an op which has a Wait() function for this purpose.
So you want a thread/goroutine to handle input/output and one to wait for the execution to end or connection to fail and handle that.

We have a number of examples for this if you’re writing in Go, for other languages, examples are a bit more sparse. I believe pylxd has some support for this in python though.

@stgraber Im using C# in this case. Yeah im aware these websockets exist, but i dont know what i should be connecting to based on what exec returns.

url format is <lxd IP>/<operation UUID returned by the route>/websocket?secret=<fds.0>