Hi,
For my personal purposes, I’d like to get what is displayed on the console when one type in :
root@server$ lxc {start|restart|stop} [instance] --console via javascript to display all these informations in a webapp I’m developing.
So far, here is what I did (in pseudo code) :
1 - PUT the desired state on 1.0/instances/instance/state, for example {‘action’: ‘start’, ‘record-output’:true}
2 - when readystate==4 and status==202, POST {} to 1.0/instances/instance/console to get the websocket’s console ids.
3 - open a websocket with the fetched parameters on wss://server/1.0/operations/[operation_id]/websocket?encodeURI(‘secret=’+fds[0])
4 - on event on this socket display what has been received.
However, this doesn’t seem to work fine and I must be missing something.
- when starting an instance, the websocket can’t be opened at this state, lxd answers “400 bad request” because the container is not in an state where the console is available. So the questions here is : when should I launch the websocket’s connection ? And when can I detect that the container is completely started so that I can release the websocket’s connexion ?
- when restarting an instance, we get only the end of the console’s messages :
“Sending SIGTEM to all remaining processes…
Sending SIGKILL to all remaining processes…
Halting system”
All that is before what happened (the stopping of all daemons is not fetched, the connection to the websocket must happen too late. Is there a way to get all messages ?
And, as you might have anticipated, the start of the instance don’t display anything since the whole have been stopped, the connection to the websocket is destroyed… - when stopping an instance, we fall with the same problems as the first part of the restarting process. I guess that this could be solved by connecting to the websocket before putting the “stop” action.
Any clue to have this working as I expect would be kind, mainly for the start process.
Regards.