`lxc console --show-log` gives confusing output
lxc console --show-log only returns new log messages that were generated after the command was last run. However, if there are no new messages, the command returns Error: open : no such file or directory instead of a message that indicates that there are no new messages.
ubuntu@ru-fu01:~$ lxc console present-mollusk --show-log
Console log:
systemd 249.11-0ubuntu3.11 running in system mode (+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT +GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY -P11KIT -QRENCODE +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified)
[...]
Ubuntu 22.04.3 LTS present-mollusk console
present-mollusk login:
ubuntu@ru-fu01:~$ lxc console present-mollusk --show-log
Error: open : no such file or directory
When running lxc console --show-log on a VM, the error message is Error: Instance is not container type. Neither the help nor the documentation say that the command is only for containers. Should it work for both VMs and containers, or do we need to update the documentation?
ubuntu@ru-fu01:~$ lxc console my-vm --show-log
Error: Instance is not container type
Finally, when running the corresponding API query, the output is the same if there are no new log messages, but if there are, the output is even more confusing:
ubuntu@ru-fu01:~$ lxc query --request GET /1.0/instances/present-mollusk/console
Error: open : no such file or directory
ubuntu@ru-fu01:~$ lxc restart present-mollusk
ubuntu@ru-fu01:~$ lxc query --request GET /1.0/instances/present-mollusk/console
Error: invalid character 's' looking for beginning of value
ubuntu@ru-fu01:~$ lxc query --request GET /1.0/instances/present-mollusk/console
Error: invalid character 'O' looking for beginning of value
ubuntu@ru-fu01:~$ lxc query --request GET /1.0/instances/present-mollusk/console
Error: invalid character 'U' looking for beginning of value
ubuntu@ru-fu01:~$ lxc query --request GET /1.0/instances/present-mollusk/console
Error: open : no such file or directory
Hello @tomponline, @ru-fu please I would like to work on this issue
Thanks!
Hello @tomponline, So i observed one has to restart a container instance before, one could get the actual logs from the
lxc console --show-log , without getting the error message Error: open : no such file or directory
lxc stop ubuntupool
lxc start ubuntupool
lxc console ubuntupool --show-log
Console log:
systemd 255.4-1ubuntu8 running in system mode (+PAM +AUDIT +SELINUX +APPARMOR +IMA +SMACK +SECCOMP +GCRYPT -GNUTLS +OPENSSL +ACL +BLKID +CURL +ELFUTILS +FIDO2 +IDN2 -IDN +IPTC +KMOD +LIBCRYPTSETUP +LIBFDISK +PCRE2 -PWQUALITY +P11KIT +QRENCODE +TPM2 +BZIP2 +LZ4 +XZ +ZLIB +ZSTD -BPF_FRAMEWORK -XKBCOMMON +UTMP +SYSVINIT default-hierarchy=unified)
Detected virtualization lxc.
Detected architecture x86-64.
Welcome to Ubuntu 24.04 LTS!
When i retry the command without restarting the instance i get
lxc console ubuntupool --show-log
Error: open : no such file or directory
The GetInstanceConsoleLog() is what returns the error message Error: open : no such file or directory
I am still looking through on how to fix this , but can it be indicated in the docs when the users
lxc console --show-log command , they will have to stop and start the lxd container instance ?
I am still looking through on how to fix this , but can it be indicated in the docs when the users
lxc console --show-logcommand , they will have to stop and start the lxd container instance ?
I think this would be misleading - if I understand it correctly, the error occurs if there are no new messages. If I restart the container before showing the log, I generate new messages, so the error won't occur. But if I want to see existing messages and I restart the container first, the messages I want to see will probably disappear.
@Philip-21 Are you still wanting to work on this issue?
It looks like support for VM's was never added; the check was introduced as a part of the container -> instance refactor. Only containers support log output; while there might be a serial console of some kind for qemu (I'd need to do some more reading), it's likely not analogous to lxc's console_log ringbuffer. These docs appear to have been updated.
Regarding the lxc query output, it looks like it tries to parse the response as json, and then instead of capturing & reinterpreting the response body it resends the request. The current client APIs don't easily allow this behavior to change. I'll see if I can improve this tomorrow.
PR for all of this will be up tomorrow afternoon.