I’m starting a console operation using: (Host and Containers are running Ubuntu 18.04 with LXD 3.18)
curl -k -X POST --cert /vagrant/lxd.crt --key /vagrant/lxd.key https:/127.0.0.1:8443/1.0/containers/c3/console -d '{"width": 80, "height": 24}' | jq
Then using a command line websocket tool, I’m connecting to the operation websocket for the console using the UUID/secret provided from the above API call:
websocat -kvb wss://127.0.0.1:8443/1.0/operations/7f8c710a-c485-46d8-80ba-9e9bd0eff144/websocket?secret=dc95c8720314ef7abb5d5e998ef57d49bd0b25b493c7032dedd78ed15cb34c7d
This works I’m able to interact and login via the console, however I don’t know how to “detach” from the console.
Closing the websocket connection doesn’t seem to detach the console. When I call the operations API / websocket again or from the command line I get the errors below which I believe means the console is still in use by another process.
Websocket:
[INFO websocat::ws_client_peer] Connected to ws
Error: Failed running forkconsole: "attaching to the container failed"
Command line:
ubuntu-bionic:~$ lxc console c3
To detach from the console, press: <ctrl>+a q
Error: Failed running forkconsole: "attaching to the container failed"
Error: exit status 1
Other issues:
When you close the websocket connection to the console operation and then reconnect to it again (using the same uuid/secret), interaction with the console no longer seems to work however the console is still attached somehow based on the error messages above. If you start a new console operation and connect to that websocket with the new uuid/secret, then you get the error message from above.
Also may_cancel is set to false for console operations so I’m unable to use the DELETE command to stop that operation. This would be a nice to have for the API to stop any “orphaned” console operations, since I’m unable to find a way to “resume” a previous websocket console operation OR a way to timeout a console operation after X amount of inactivity.
I understand that Ctrl + A then q is used to detach from the console using the lxc console
command, but sending those characters via the websocket doesn’t seem to work. Also using Ctrl + c (SIGTERM?) doesn’t seem to work either.
** (I looked through the code at https://github.com/lxc/lxd/blob/873f6e045c291027fe4eba9ab7377cb0a248afde/lxd/container_console.go and I’m not very familiar with GO, but does that mean it’s looking for a SIGTERM to detach the console?)
Thank you in advance for any insight! I really appreciate it.