Improve VM shutdown
Includes cherry picks from https://github.com/lxc/incus/pull/362
@hamistao ready for review?
@tomponline This is still missing working tests for 129 exit code in containers, as there weren't any before. I am still busy with the API metrics but I will return to this as soon as I finish the changes on the metrics PR.
@hamistao ready for a review, is there an accompanying test for this in lxd-ci?
@mihalicyn Thanks for the review, but my main question was regarding the failing tests. Although the VM case is currently working as expected, container disconnections result in a 137 exit code instead of 129 on my local tests. I wanted to confirm if this behavior can be considered a bug and if just catching this exit code and changing it to 129 would be an adequate solution or if there could be a deeper problem involved.
Also, the GH tests behave differentely from my local tests and return a 143 exit code, @simondeziel discovered that this exit code is also what we get when killing the agent process inside the instance to make it disconnect.
@tomponline This is ready for a review, the PR containing the tests was also opened here. When both are merged I will also add tests for containers on the LXD repo.